errorcode.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // Copyright 2007 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview Error codes shared between goog.net.IframeIo and
  16. * goog.net.XhrIo.
  17. */
  18. goog.provide('goog.net.ErrorCode');
  19. /**
  20. * Error codes
  21. * @enum {number}
  22. */
  23. goog.net.ErrorCode = {
  24. /**
  25. * There is no error condition.
  26. */
  27. NO_ERROR: 0,
  28. /**
  29. * The most common error from iframeio, unfortunately, is that the browser
  30. * responded with an error page that is classed as a different domain. The
  31. * situations, are when a browser error page is shown -- 404, access denied,
  32. * DNS failure, connection reset etc.)
  33. *
  34. */
  35. ACCESS_DENIED: 1,
  36. /**
  37. * Currently the only case where file not found will be caused is when the
  38. * code is running on the local file system and a non-IE browser makes a
  39. * request to a file that doesn't exist.
  40. */
  41. FILE_NOT_FOUND: 2,
  42. /**
  43. * If Firefox shows a browser error page, such as a connection reset by
  44. * server or access denied, then it will fail silently without the error or
  45. * load handlers firing.
  46. */
  47. FF_SILENT_ERROR: 3,
  48. /**
  49. * Custom error provided by the client through the error check hook.
  50. */
  51. CUSTOM_ERROR: 4,
  52. /**
  53. * Exception was thrown while processing the request.
  54. */
  55. EXCEPTION: 5,
  56. /**
  57. * The Http response returned a non-successful http status code.
  58. */
  59. HTTP_ERROR: 6,
  60. /**
  61. * The request was aborted.
  62. */
  63. ABORT: 7,
  64. /**
  65. * The request timed out.
  66. */
  67. TIMEOUT: 8,
  68. /**
  69. * The resource is not available offline.
  70. */
  71. OFFLINE: 9
  72. };
  73. /**
  74. * Returns a friendly error message for an error code. These messages are for
  75. * debugging and are not localized.
  76. * @param {goog.net.ErrorCode} errorCode An error code.
  77. * @return {string} A message for debugging.
  78. */
  79. goog.net.ErrorCode.getDebugMessage = function(errorCode) {
  80. switch (errorCode) {
  81. case goog.net.ErrorCode.NO_ERROR:
  82. return 'No Error';
  83. case goog.net.ErrorCode.ACCESS_DENIED:
  84. return 'Access denied to content document';
  85. case goog.net.ErrorCode.FILE_NOT_FOUND:
  86. return 'File not found';
  87. case goog.net.ErrorCode.FF_SILENT_ERROR:
  88. return 'Firefox silently errored';
  89. case goog.net.ErrorCode.CUSTOM_ERROR:
  90. return 'Application custom error';
  91. case goog.net.ErrorCode.EXCEPTION:
  92. return 'An exception occurred';
  93. case goog.net.ErrorCode.HTTP_ERROR:
  94. return 'Http response at 400 or 500 level';
  95. case goog.net.ErrorCode.ABORT:
  96. return 'Request was aborted';
  97. case goog.net.ErrorCode.TIMEOUT:
  98. return 'Request timed out';
  99. case goog.net.ErrorCode.OFFLINE:
  100. return 'The resource is not available offline';
  101. default:
  102. return 'Unrecognized error code';
  103. }
  104. };