@atlaskit/media-client 28.5.0 → 28.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/cjs/client/file-fetcher/error.js +5 -7
- package/dist/cjs/client/file-fetcher/index.js +135 -71
- package/dist/cjs/client/media-client.js +1 -2
- package/dist/cjs/client/media-store/MediaStore.js +10 -3
- package/dist/cjs/client/media-store/error.js +5 -7
- package/dist/cjs/client/mobile-upload.js +1 -2
- package/dist/cjs/client/stargate-client.js +1 -2
- package/dist/cjs/file-streams-cache.js +1 -2
- package/dist/cjs/models/errors/index.js +6 -8
- package/dist/cjs/upload-controller.js +1 -2
- package/dist/cjs/uploader/error.js +5 -7
- package/dist/cjs/utils/hashing/sha256SimpleHasher.js +1 -2
- package/dist/cjs/utils/hashing/simpleHasher.js +1 -2
- package/dist/cjs/utils/hashing/workerHasher.js +1 -2
- package/dist/cjs/utils/mobileUpload/error.js +5 -7
- package/dist/cjs/utils/polling/errors.js +5 -7
- package/dist/cjs/utils/polling/index.js +1 -2
- package/dist/cjs/utils/request/errors.js +5 -7
- package/dist/cjs/utils/request/helpers.js +10 -4
- package/dist/es2019/client/file-fetcher/index.js +38 -8
- package/dist/es2019/client/media-store/MediaStore.js +11 -3
- package/dist/es2019/utils/request/helpers.js +7 -2
- package/dist/esm/client/file-fetcher/error.js +5 -7
- package/dist/esm/client/file-fetcher/index.js +135 -71
- package/dist/esm/client/media-client.js +1 -2
- package/dist/esm/client/media-store/MediaStore.js +12 -5
- package/dist/esm/client/media-store/error.js +5 -7
- package/dist/esm/client/mobile-upload.js +1 -2
- package/dist/esm/client/stargate-client.js +1 -2
- package/dist/esm/file-streams-cache.js +1 -2
- package/dist/esm/models/errors/index.js +6 -8
- package/dist/esm/upload-controller.js +1 -2
- package/dist/esm/uploader/error.js +5 -7
- package/dist/esm/utils/hashing/sha256SimpleHasher.js +1 -2
- package/dist/esm/utils/hashing/simpleHasher.js +1 -2
- package/dist/esm/utils/hashing/workerHasher.js +1 -2
- package/dist/esm/utils/mobileUpload/error.js +5 -7
- package/dist/esm/utils/polling/errors.js +5 -7
- package/dist/esm/utils/polling/index.js +1 -2
- package/dist/esm/utils/request/errors.js +5 -7
- package/dist/esm/utils/request/helpers.js +9 -4
- package/dist/types/client/file-fetcher/index.d.ts +4 -2
- package/dist/types/utils/request/helpers.d.ts +1 -0
- package/dist/types/utils/request/types.d.ts +1 -0
- package/dist/types-ts4.5/client/file-fetcher/index.d.ts +4 -2
- package/dist/types-ts4.5/utils/request/helpers.d.ts +1 -0
- package/dist/types-ts4.5/utils/request/types.d.ts +1 -0
- package/package.json +1 -1
|
@@ -8,25 +8,24 @@ exports.MobileUploadError = void 0;
|
|
|
8
8
|
exports.isMobileUploadError = isMobileUploadError;
|
|
9
9
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
10
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
11
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
12
11
|
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
13
12
|
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
13
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
14
14
|
var _errors = require("../../models/errors");
|
|
15
|
-
function
|
|
15
|
+
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
|
|
16
16
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
17
17
|
var MobileUploadError = exports.MobileUploadError = /*#__PURE__*/function (_BaseMediaClientError) {
|
|
18
|
-
(0, _inherits2.default)(MobileUploadError, _BaseMediaClientError);
|
|
19
|
-
var _super = _createSuper(MobileUploadError);
|
|
20
18
|
function MobileUploadError(reason, id, metadata) {
|
|
21
19
|
var _this;
|
|
22
20
|
(0, _classCallCheck2.default)(this, MobileUploadError);
|
|
23
|
-
_this =
|
|
21
|
+
_this = _callSuper(this, MobileUploadError, [reason]);
|
|
24
22
|
_this.reason = reason;
|
|
25
23
|
_this.id = id;
|
|
26
24
|
_this.metadata = metadata;
|
|
27
25
|
return _this;
|
|
28
26
|
}
|
|
29
|
-
(0,
|
|
27
|
+
(0, _inherits2.default)(MobileUploadError, _BaseMediaClientError);
|
|
28
|
+
return (0, _createClass2.default)(MobileUploadError, [{
|
|
30
29
|
key: "attributes",
|
|
31
30
|
get: function get() {
|
|
32
31
|
var reason = this.reason,
|
|
@@ -47,7 +46,6 @@ var MobileUploadError = exports.MobileUploadError = /*#__PURE__*/function (_Base
|
|
|
47
46
|
};
|
|
48
47
|
}
|
|
49
48
|
}]);
|
|
50
|
-
return MobileUploadError;
|
|
51
49
|
}(_errors.BaseMediaClientError);
|
|
52
50
|
function isMobileUploadError(err) {
|
|
53
51
|
return err instanceof MobileUploadError;
|
|
@@ -8,24 +8,23 @@ exports.PollingError = void 0;
|
|
|
8
8
|
exports.isPollingError = isPollingError;
|
|
9
9
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
10
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
11
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
12
11
|
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
13
12
|
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
13
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
14
14
|
var _errors = require("../../models/errors");
|
|
15
|
-
function
|
|
15
|
+
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
|
|
16
16
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
17
17
|
var PollingError = exports.PollingError = /*#__PURE__*/function (_BaseMediaClientError) {
|
|
18
|
-
(0, _inherits2.default)(PollingError, _BaseMediaClientError);
|
|
19
|
-
var _super = _createSuper(PollingError);
|
|
20
18
|
function PollingError(reason, attempts) {
|
|
21
19
|
var _this;
|
|
22
20
|
(0, _classCallCheck2.default)(this, PollingError);
|
|
23
|
-
_this =
|
|
21
|
+
_this = _callSuper(this, PollingError, [reason]);
|
|
24
22
|
_this.reason = reason;
|
|
25
23
|
_this.attempts = attempts;
|
|
26
24
|
return _this;
|
|
27
25
|
}
|
|
28
|
-
(0,
|
|
26
|
+
(0, _inherits2.default)(PollingError, _BaseMediaClientError);
|
|
27
|
+
return (0, _createClass2.default)(PollingError, [{
|
|
29
28
|
key: "attributes",
|
|
30
29
|
get: function get() {
|
|
31
30
|
var reason = this.reason,
|
|
@@ -36,7 +35,6 @@ var PollingError = exports.PollingError = /*#__PURE__*/function (_BaseMediaClien
|
|
|
36
35
|
};
|
|
37
36
|
}
|
|
38
37
|
}]);
|
|
39
|
-
return PollingError;
|
|
40
38
|
}(_errors.BaseMediaClientError);
|
|
41
39
|
function isPollingError(err) {
|
|
42
40
|
return err instanceof PollingError;
|
|
@@ -54,7 +54,7 @@ var PollingFunction = exports.PollingFunction = /*#__PURE__*/function () {
|
|
|
54
54
|
this.options = _objectSpread(_objectSpread({}, defaultPollingOptions), options);
|
|
55
55
|
this.poll_intervalMs = this.options.poll_intervalMs;
|
|
56
56
|
}
|
|
57
|
-
(0, _createClass2.default)(PollingFunction, [{
|
|
57
|
+
return (0, _createClass2.default)(PollingFunction, [{
|
|
58
58
|
key: "execute",
|
|
59
59
|
value: function () {
|
|
60
60
|
var _execute = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(executor) {
|
|
@@ -141,5 +141,4 @@ var PollingFunction = exports.PollingFunction = /*#__PURE__*/function () {
|
|
|
141
141
|
this.timeoutId = 0;
|
|
142
142
|
}
|
|
143
143
|
}]);
|
|
144
|
-
return PollingFunction;
|
|
145
144
|
}();
|
|
@@ -8,25 +8,24 @@ exports.RequestError = void 0;
|
|
|
8
8
|
exports.isRequestError = isRequestError;
|
|
9
9
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
10
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
11
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
12
11
|
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
13
12
|
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
13
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
14
14
|
var _errors = require("../../models/errors");
|
|
15
|
-
function
|
|
15
|
+
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
|
|
16
16
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
17
17
|
var RequestError = exports.RequestError = /*#__PURE__*/function (_BaseMediaClientError) {
|
|
18
|
-
(0, _inherits2.default)(RequestError, _BaseMediaClientError);
|
|
19
|
-
var _super = _createSuper(RequestError);
|
|
20
18
|
function RequestError(reason, metadata, innerError) {
|
|
21
19
|
var _this;
|
|
22
20
|
(0, _classCallCheck2.default)(this, RequestError);
|
|
23
|
-
_this =
|
|
21
|
+
_this = _callSuper(this, RequestError, [reason]);
|
|
24
22
|
_this.reason = reason;
|
|
25
23
|
_this.metadata = metadata;
|
|
26
24
|
_this.innerError = innerError;
|
|
27
25
|
return _this;
|
|
28
26
|
}
|
|
29
|
-
(0,
|
|
27
|
+
(0, _inherits2.default)(RequestError, _BaseMediaClientError);
|
|
28
|
+
return (0, _createClass2.default)(RequestError, [{
|
|
30
29
|
key: "attributes",
|
|
31
30
|
get: function get() {
|
|
32
31
|
var reason = this.reason,
|
|
@@ -57,7 +56,6 @@ var RequestError = exports.RequestError = /*#__PURE__*/function (_BaseMediaClien
|
|
|
57
56
|
};
|
|
58
57
|
}
|
|
59
58
|
}]);
|
|
60
|
-
return RequestError;
|
|
61
59
|
}(_errors.BaseMediaClientError);
|
|
62
60
|
function isRequestError(err) {
|
|
63
61
|
return err instanceof RequestError;
|
|
@@ -12,6 +12,7 @@ exports.createProcessFetchResponse = createProcessFetchResponse;
|
|
|
12
12
|
exports.createRequestErrorFromResponse = createRequestErrorFromResponse;
|
|
13
13
|
exports.createRequestErrorReason = createRequestErrorReason;
|
|
14
14
|
exports.createUrl = createUrl;
|
|
15
|
+
exports.defaultShouldRetryError = void 0;
|
|
15
16
|
exports.extendHeaders = extendHeaders;
|
|
16
17
|
exports.extendTraceContext = void 0;
|
|
17
18
|
exports.extractMediaHeaders = extractMediaHeaders;
|
|
@@ -61,8 +62,7 @@ var ZipkinHeaderKeys = exports.ZipkinHeaderKeys = {
|
|
|
61
62
|
flags: 'x-b3-flags'
|
|
62
63
|
};
|
|
63
64
|
var mapTraceIdToRequestHeaders = function mapTraceIdToRequestHeaders(traceContext) {
|
|
64
|
-
|
|
65
|
-
return traceContext ? (_ref = {}, (0, _defineProperty2.default)(_ref, ZipkinHeaderKeys.traceId, traceContext.traceId), (0, _defineProperty2.default)(_ref, ZipkinHeaderKeys.spanId, traceContext.spanId), _ref) : {};
|
|
65
|
+
return traceContext ? (0, _defineProperty2.default)((0, _defineProperty2.default)({}, ZipkinHeaderKeys.traceId, traceContext.traceId), ZipkinHeaderKeys.spanId, traceContext.spanId) : {};
|
|
66
66
|
};
|
|
67
67
|
function mapAuthToRequestHeaders(auth) {
|
|
68
68
|
if (!auth) {
|
|
@@ -159,6 +159,10 @@ function createMapResponseToBlob(metadata) {
|
|
|
159
159
|
};
|
|
160
160
|
}();
|
|
161
161
|
}
|
|
162
|
+
var defaultShouldRetryError = exports.defaultShouldRetryError = function defaultShouldRetryError(err) {
|
|
163
|
+
var _err$metadata;
|
|
164
|
+
return isFetchNetworkError(err) || (0, _errors.isRequestError)(err) && !!(err !== null && err !== void 0 && (_err$metadata = err.metadata) !== null && _err$metadata !== void 0 && _err$metadata.statusCode) && err.metadata.statusCode >= 500;
|
|
165
|
+
};
|
|
162
166
|
var DEFAULT_RETRY_OPTIONS = exports.DEFAULT_RETRY_OPTIONS = {
|
|
163
167
|
startTimeoutInMs: 1000,
|
|
164
168
|
// 1 second is generally a good timeout to start
|
|
@@ -182,6 +186,8 @@ function _fetchRetry() {
|
|
|
182
186
|
startTimeoutInMs,
|
|
183
187
|
maxAttempts,
|
|
184
188
|
factor,
|
|
189
|
+
_options$shouldRetryE,
|
|
190
|
+
shouldRetryError,
|
|
185
191
|
attempts,
|
|
186
192
|
timeoutInMs,
|
|
187
193
|
lastError,
|
|
@@ -192,7 +198,7 @@ function _fetchRetry() {
|
|
|
192
198
|
case 0:
|
|
193
199
|
overwriteOptions = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : {};
|
|
194
200
|
options = _objectSpread(_objectSpread({}, DEFAULT_RETRY_OPTIONS), overwriteOptions);
|
|
195
|
-
startTimeoutInMs = options.startTimeoutInMs, maxAttempts = options.maxAttempts, factor = options.factor;
|
|
201
|
+
startTimeoutInMs = options.startTimeoutInMs, maxAttempts = options.maxAttempts, factor = options.factor, _options$shouldRetryE = options.shouldRetryError, shouldRetryError = _options$shouldRetryE === void 0 ? defaultShouldRetryError : _options$shouldRetryE;
|
|
196
202
|
attempts = 0;
|
|
197
203
|
timeoutInMs = startTimeoutInMs;
|
|
198
204
|
waitAndBumpTimeout = /*#__PURE__*/function () {
|
|
@@ -237,7 +243,7 @@ function _fetchRetry() {
|
|
|
237
243
|
}
|
|
238
244
|
throw new _errors.RequestError('clientAbortedRequest', metadata, _context4.t0);
|
|
239
245
|
case 18:
|
|
240
|
-
if (
|
|
246
|
+
if (shouldRetryError(_context4.t0)) {
|
|
241
247
|
_context4.next = 20;
|
|
242
248
|
break;
|
|
243
249
|
}
|
|
@@ -26,6 +26,8 @@ import { PollingFunction } from '../../utils/polling';
|
|
|
26
26
|
import { isEmptyFile } from '../../utils/detectEmptyFile';
|
|
27
27
|
import { mediaStore } from '@atlaskit/media-state';
|
|
28
28
|
export { isFileFetcherError, FileFetcherError } from './error';
|
|
29
|
+
const isCopySourceFileWithToken = token => !!token.authProvider;
|
|
30
|
+
const isCopyDestinationWithToken = token => !!token.authProvider;
|
|
29
31
|
export class FileFetcherImpl {
|
|
30
32
|
constructor(mediaApi, store = mediaStore) {
|
|
31
33
|
_defineProperty(this, "getErrorFileState", (error, id, occurrenceKey) => {
|
|
@@ -379,7 +381,7 @@ export class FileFetcherImpl {
|
|
|
379
381
|
traceContext
|
|
380
382
|
});
|
|
381
383
|
}
|
|
382
|
-
async
|
|
384
|
+
async copyFileWithToken(source, destination, traceContext) {
|
|
383
385
|
const {
|
|
384
386
|
authProvider,
|
|
385
387
|
collection: sourceCollection,
|
|
@@ -391,10 +393,6 @@ export class FileFetcherImpl {
|
|
|
391
393
|
replaceFileId,
|
|
392
394
|
occurrenceKey
|
|
393
395
|
} = destination;
|
|
394
|
-
const {
|
|
395
|
-
preview,
|
|
396
|
-
mimeType
|
|
397
|
-
} = options;
|
|
398
396
|
const mediaStore = destination.mediaStore || new MediaApi({
|
|
399
397
|
authProvider: destinationAuthProvider
|
|
400
398
|
});
|
|
@@ -413,12 +411,44 @@ export class FileFetcherImpl {
|
|
|
413
411
|
replaceFileId,
|
|
414
412
|
occurrenceKey
|
|
415
413
|
};
|
|
414
|
+
const {
|
|
415
|
+
data
|
|
416
|
+
} = await mediaStore.copyFileWithToken(body, params, traceContext);
|
|
417
|
+
return data;
|
|
418
|
+
}
|
|
419
|
+
async copyFileWithIntent(source, destination, traceContext) {
|
|
420
|
+
const res = await this.mediaApi.copyFile(source.id, {
|
|
421
|
+
sourceCollection: source.collection,
|
|
422
|
+
collection: destination.collection,
|
|
423
|
+
replaceFileId: destination.replaceFileId
|
|
424
|
+
}, traceContext);
|
|
425
|
+
const {
|
|
426
|
+
data
|
|
427
|
+
} = res;
|
|
428
|
+
return data;
|
|
429
|
+
}
|
|
430
|
+
async copyFile(source, destination, options = {}, traceContext) {
|
|
431
|
+
const {
|
|
432
|
+
id
|
|
433
|
+
} = source;
|
|
434
|
+
const {
|
|
435
|
+
collection: destinationCollectionName,
|
|
436
|
+
replaceFileId,
|
|
437
|
+
occurrenceKey
|
|
438
|
+
} = destination;
|
|
439
|
+
const {
|
|
440
|
+
preview,
|
|
441
|
+
mimeType
|
|
442
|
+
} = options;
|
|
416
443
|
const cache = getFileStreamsCache();
|
|
417
444
|
let processingSubscription;
|
|
418
445
|
try {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
446
|
+
let copiedFile;
|
|
447
|
+
if (isCopySourceFileWithToken(source) && isCopyDestinationWithToken(destination)) {
|
|
448
|
+
copiedFile = await this.copyFileWithToken(source, destination, traceContext);
|
|
449
|
+
} else {
|
|
450
|
+
copiedFile = await this.copyFileWithIntent(source, destination, traceContext);
|
|
451
|
+
}
|
|
422
452
|
|
|
423
453
|
// if we were passed a "mimeType", we propagate it into copiedFileWithMimeType
|
|
424
454
|
const copiedFileWithMimeType = {
|
|
@@ -2,8 +2,8 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
2
2
|
import { isClientBasedAuth } from '@atlaskit/media-core';
|
|
3
3
|
import { FILE_CACHE_MAX_AGE, MAX_RESOLUTION } from '../../constants';
|
|
4
4
|
import { getArtifactUrl } from '../../models/artifacts';
|
|
5
|
-
import { request } from '../../utils/request';
|
|
6
|
-
import { createUrl, createMapResponseToJson, createMapResponseToBlob, extendTraceContext } from '../../utils/request/helpers';
|
|
5
|
+
import { isRequestError, request } from '../../utils/request';
|
|
6
|
+
import { createUrl, createMapResponseToJson, createMapResponseToBlob, defaultShouldRetryError, extendTraceContext } from '../../utils/request/helpers';
|
|
7
7
|
import { mapToMediaCdnUrl } from '../../utils/mediaCdn';
|
|
8
8
|
import { resolveAuth, resolveInitialAuth } from './resolveAuth';
|
|
9
9
|
import { ChunkHashAlgorithm } from '@atlaskit/media-core';
|
|
@@ -365,7 +365,15 @@ export class MediaStore {
|
|
|
365
365
|
body: JSON.stringify({
|
|
366
366
|
id
|
|
367
367
|
}),
|
|
368
|
-
traceContext
|
|
368
|
+
traceContext,
|
|
369
|
+
clientOptions: {
|
|
370
|
+
retryOptions: {
|
|
371
|
+
shouldRetryError: err => {
|
|
372
|
+
var _err$metadata;
|
|
373
|
+
return defaultShouldRetryError(err) || isRequestError(err) && (err === null || err === void 0 ? void 0 : (_err$metadata = err.metadata) === null || _err$metadata === void 0 ? void 0 : _err$metadata.statusCode) === 401;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
369
377
|
};
|
|
370
378
|
return this.request('/v2/file/copy', options).then(createMapResponseToJson(metadata));
|
|
371
379
|
}
|
|
@@ -100,6 +100,10 @@ export function createMapResponseToBlob(metadata) {
|
|
|
100
100
|
}
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
|
+
export const defaultShouldRetryError = err => {
|
|
104
|
+
var _err$metadata;
|
|
105
|
+
return isFetchNetworkError(err) || isRequestError(err) && !!(err !== null && err !== void 0 && (_err$metadata = err.metadata) !== null && _err$metadata !== void 0 && _err$metadata.statusCode) && err.metadata.statusCode >= 500;
|
|
106
|
+
};
|
|
103
107
|
export const DEFAULT_RETRY_OPTIONS = {
|
|
104
108
|
startTimeoutInMs: 1000,
|
|
105
109
|
// 1 second is generally a good timeout to start
|
|
@@ -126,7 +130,8 @@ export async function fetchRetry(functionToRetry, metadata, overwriteOptions = {
|
|
|
126
130
|
const {
|
|
127
131
|
startTimeoutInMs,
|
|
128
132
|
maxAttempts,
|
|
129
|
-
factor
|
|
133
|
+
factor,
|
|
134
|
+
shouldRetryError = defaultShouldRetryError
|
|
130
135
|
} = options;
|
|
131
136
|
let attempts = 0;
|
|
132
137
|
let timeoutInMs = startTimeoutInMs;
|
|
@@ -146,7 +151,7 @@ export async function fetchRetry(functionToRetry, metadata, overwriteOptions = {
|
|
|
146
151
|
if (isAbortedRequestError(err)) {
|
|
147
152
|
throw new RequestError('clientAbortedRequest', metadata, err);
|
|
148
153
|
}
|
|
149
|
-
if (!
|
|
154
|
+
if (!shouldRetryError(err)) {
|
|
150
155
|
throw err;
|
|
151
156
|
}
|
|
152
157
|
await waitAndBumpTimeout();
|
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
3
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
|
-
import _inherits from "@babel/runtime/helpers/inherits";
|
|
5
4
|
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
6
5
|
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
6
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
7
7
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
8
8
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
9
|
-
function
|
|
9
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
10
10
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
11
11
|
import { BaseMediaClientError } from '../../models/errors';
|
|
12
12
|
export var FileFetcherError = /*#__PURE__*/function (_BaseMediaClientError) {
|
|
13
|
-
_inherits(FileFetcherError, _BaseMediaClientError);
|
|
14
|
-
var _super = _createSuper(FileFetcherError);
|
|
15
13
|
function FileFetcherError(reason, id, metadata) {
|
|
16
14
|
var _this;
|
|
17
15
|
_classCallCheck(this, FileFetcherError);
|
|
18
|
-
_this =
|
|
16
|
+
_this = _callSuper(this, FileFetcherError, [reason]);
|
|
19
17
|
_this.reason = reason;
|
|
20
18
|
_this.id = id;
|
|
21
19
|
_this.metadata = metadata;
|
|
22
20
|
return _this;
|
|
23
21
|
}
|
|
24
|
-
|
|
22
|
+
_inherits(FileFetcherError, _BaseMediaClientError);
|
|
23
|
+
return _createClass(FileFetcherError, [{
|
|
25
24
|
key: "attributes",
|
|
26
25
|
get: function get() {
|
|
27
26
|
var reason = this.reason,
|
|
@@ -43,7 +42,6 @@ export var FileFetcherError = /*#__PURE__*/function (_BaseMediaClientError) {
|
|
|
43
42
|
});
|
|
44
43
|
}
|
|
45
44
|
}]);
|
|
46
|
-
return FileFetcherError;
|
|
47
45
|
}(BaseMediaClientError);
|
|
48
46
|
export function isFileFetcherError(err) {
|
|
49
47
|
return err instanceof FileFetcherError;
|