index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
  3. var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
  4. _Object$defineProperty(exports, "__esModule", {
  5. value: true
  6. });
  7. exports.QiniuNetworkError = exports.QiniuRequestError = exports.QiniuError = exports.QiniuErrorName = void 0;
  8. var _create = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/create"));
  9. var _setPrototypeOf = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/set-prototype-of"));
  10. var __extends = void 0 && (void 0).__extends || function () {
  11. var _extendStatics = function extendStatics(d, b) {
  12. _extendStatics = _setPrototypeOf["default"] || {
  13. __proto__: []
  14. } instanceof Array && function (d, b) {
  15. d.__proto__ = b;
  16. } || function (d, b) {
  17. for (var p in b) {
  18. if (b.hasOwnProperty(p)) d[p] = b[p];
  19. }
  20. };
  21. return _extendStatics(d, b);
  22. };
  23. return function (d, b) {
  24. _extendStatics(d, b);
  25. function __() {
  26. this.constructor = d;
  27. }
  28. d.prototype = b === null ? (0, _create["default"])(b) : (__.prototype = b.prototype, new __());
  29. };
  30. }();
  31. var QiniuErrorName;
  32. exports.QiniuErrorName = QiniuErrorName;
  33. (function (QiniuErrorName) {
  34. // 输入错误
  35. QiniuErrorName["InvalidFile"] = "InvalidFile";
  36. QiniuErrorName["InvalidToken"] = "InvalidToken";
  37. QiniuErrorName["InvalidMetadata"] = "InvalidMetadata";
  38. QiniuErrorName["InvalidChunkSize"] = "InvalidChunkSize";
  39. QiniuErrorName["InvalidCustomVars"] = "InvalidCustomVars";
  40. QiniuErrorName["NotAvailableUploadHost"] = "NotAvailableUploadHost"; // 缓存相关
  41. QiniuErrorName["ReadCacheFailed"] = "ReadCacheFailed";
  42. QiniuErrorName["InvalidCacheData"] = "InvalidCacheData";
  43. QiniuErrorName["WriteCacheFailed"] = "WriteCacheFailed";
  44. QiniuErrorName["RemoveCacheFailed"] = "RemoveCacheFailed"; // 图片压缩模块相关
  45. QiniuErrorName["GetCanvasContextFailed"] = "GetCanvasContextFailed";
  46. QiniuErrorName["UnsupportedFileType"] = "UnsupportedFileType"; // 运行环境相关
  47. QiniuErrorName["FileReaderReadFailed"] = "FileReaderReadFailed";
  48. QiniuErrorName["NotAvailableXMLHttpRequest"] = "NotAvailableXMLHttpRequest";
  49. QiniuErrorName["InvalidProgressEventTarget"] = "InvalidProgressEventTarget"; // 请求错误
  50. QiniuErrorName["RequestError"] = "RequestError";
  51. })(QiniuErrorName || (exports.QiniuErrorName = QiniuErrorName = {}));
  52. var QiniuError =
  53. /** @class */
  54. function () {
  55. function QiniuError(name, message) {
  56. this.name = name;
  57. this.message = message;
  58. this.stack = new Error().stack;
  59. }
  60. return QiniuError;
  61. }();
  62. exports.QiniuError = QiniuError;
  63. var QiniuRequestError =
  64. /** @class */
  65. function (_super) {
  66. __extends(QiniuRequestError, _super);
  67. function QiniuRequestError(code, reqId, message, data) {
  68. var _this = _super.call(this, QiniuErrorName.RequestError, message) || this;
  69. _this.code = code;
  70. _this.reqId = reqId;
  71. /**
  72. * @description 标记当前的 error 类型是一个 QiniuRequestError
  73. * @deprecated 下一个大版本将会移除,不推荐使用,推荐直接使用 instanceof 进行判断
  74. */
  75. _this.isRequestError = true;
  76. _this.data = data;
  77. return _this;
  78. }
  79. return QiniuRequestError;
  80. }(QiniuError);
  81. exports.QiniuRequestError = QiniuRequestError;
  82. /**
  83. * @description 由于跨域、证书错误、断网、host 解析失败、系统拦截等原因导致的错误
  84. */
  85. var QiniuNetworkError =
  86. /** @class */
  87. function (_super) {
  88. __extends(QiniuNetworkError, _super);
  89. function QiniuNetworkError(message, reqId) {
  90. if (reqId === void 0) {
  91. reqId = '';
  92. }
  93. return _super.call(this, 0, reqId, message) || this;
  94. }
  95. return QiniuNetworkError;
  96. }(QiniuRequestError);
  97. exports.QiniuNetworkError = QiniuNetworkError;