@atlaskit/media-client 29.1.0 → 31.0.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 +39 -0
- package/dist/cjs/client/file-fetcher/error.js +12 -10
- package/dist/cjs/client/file-fetcher/index.js +54 -61
- package/dist/cjs/client/media-store/error.js +4 -5
- package/dist/cjs/index.js +18 -0
- package/dist/cjs/models/errors/index.js +68 -5
- package/dist/cjs/models/errors/types.js +5 -1
- package/dist/cjs/models/file-state.js +4 -1
- package/dist/cjs/uploader/error.js +11 -9
- package/dist/cjs/uploader/index.js +2 -1
- package/dist/cjs/utils/mobileUpload/error.js +12 -10
- package/dist/cjs/utils/mobileUpload/helpers.js +4 -2
- package/dist/cjs/utils/polling/errors.js +6 -7
- package/dist/cjs/utils/polling/index.js +6 -2
- package/dist/cjs/utils/request/errors.js +4 -6
- package/dist/cjs/utils/request/helpers.js +8 -3
- package/dist/es2019/client/file-fetcher/error.js +10 -7
- package/dist/es2019/client/file-fetcher/index.js +36 -48
- package/dist/es2019/client/media-store/error.js +4 -3
- package/dist/es2019/index.js +2 -2
- package/dist/es2019/models/errors/index.js +62 -5
- package/dist/es2019/models/errors/types.js +1 -0
- package/dist/es2019/models/file-state.js +1 -0
- package/dist/es2019/uploader/error.js +10 -7
- package/dist/es2019/uploader/index.js +2 -1
- package/dist/es2019/utils/mobileUpload/error.js +10 -7
- package/dist/es2019/utils/mobileUpload/helpers.js +4 -2
- package/dist/es2019/utils/polling/errors.js +8 -5
- package/dist/es2019/utils/polling/index.js +6 -2
- package/dist/es2019/utils/request/errors.js +4 -4
- package/dist/es2019/utils/request/helpers.js +8 -3
- package/dist/esm/client/file-fetcher/error.js +12 -10
- package/dist/esm/client/file-fetcher/index.js +55 -62
- package/dist/esm/client/media-store/error.js +4 -5
- package/dist/esm/index.js +2 -2
- package/dist/esm/models/errors/index.js +67 -4
- package/dist/esm/models/errors/types.js +1 -0
- package/dist/esm/models/file-state.js +3 -0
- package/dist/esm/uploader/error.js +11 -9
- package/dist/esm/uploader/index.js +2 -1
- package/dist/esm/utils/mobileUpload/error.js +12 -10
- package/dist/esm/utils/mobileUpload/helpers.js +4 -2
- package/dist/esm/utils/polling/errors.js +6 -7
- package/dist/esm/utils/polling/index.js +6 -2
- package/dist/esm/utils/request/errors.js +4 -6
- package/dist/esm/utils/request/helpers.js +8 -3
- package/dist/types/client/file-fetcher/error.d.ts +9 -12
- package/dist/types/client/media-store/error.d.ts +3 -4
- package/dist/types/index.d.ts +2 -2
- package/dist/types/models/errors/index.d.ts +17 -4
- package/dist/types/models/errors/types.d.ts +7 -0
- package/dist/types/models/file-state.d.ts +2 -0
- package/dist/types/uploader/error.d.ts +8 -10
- package/dist/types/utils/mobileUpload/error.d.ts +9 -12
- package/dist/types/utils/polling/errors.d.ts +4 -5
- package/dist/types/utils/polling/types.d.ts +3 -0
- package/dist/types/utils/request/errors.d.ts +3 -5
- package/dist/types-ts4.5/client/file-fetcher/error.d.ts +9 -12
- package/dist/types-ts4.5/client/media-store/error.d.ts +3 -4
- package/dist/types-ts4.5/index.d.ts +2 -2
- package/dist/types-ts4.5/models/errors/index.d.ts +17 -4
- package/dist/types-ts4.5/models/errors/types.d.ts +7 -0
- package/dist/types-ts4.5/models/file-state.d.ts +2 -0
- package/dist/types-ts4.5/uploader/error.d.ts +8 -10
- package/dist/types-ts4.5/utils/mobileUpload/error.d.ts +9 -12
- package/dist/types-ts4.5/utils/polling/errors.d.ts +4 -5
- package/dist/types-ts4.5/utils/polling/types.d.ts +3 -0
- package/dist/types-ts4.5/utils/request/errors.d.ts +3 -5
- package/package.json +3 -3
|
@@ -15,20 +15,19 @@ var _errors = require("../../models/errors");
|
|
|
15
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
|
-
function PollingError(reason,
|
|
19
|
-
var _this;
|
|
18
|
+
function PollingError(reason, metadata) {
|
|
20
19
|
(0, _classCallCheck2.default)(this, PollingError);
|
|
21
|
-
|
|
22
|
-
_this.reason = reason;
|
|
23
|
-
_this.attempts = attempts;
|
|
24
|
-
return _this;
|
|
20
|
+
return _callSuper(this, PollingError, [reason, metadata, undefined]);
|
|
25
21
|
}
|
|
22
|
+
|
|
23
|
+
// TODO: Deprecate this getter https://product-fabric.atlassian.net/browse/CXP-4665
|
|
24
|
+
/** Will be deprecated. Use the properties `reason` and `metadata` instead */
|
|
26
25
|
(0, _inherits2.default)(PollingError, _BaseMediaClientError);
|
|
27
26
|
return (0, _createClass2.default)(PollingError, [{
|
|
28
27
|
key: "attributes",
|
|
29
28
|
get: function get() {
|
|
30
29
|
var reason = this.reason,
|
|
31
|
-
attempts = this.attempts;
|
|
30
|
+
attempts = this.metadata.attempts;
|
|
32
31
|
return {
|
|
33
32
|
reason: reason,
|
|
34
33
|
attempts: attempts
|
|
@@ -68,7 +68,9 @@ var PollingFunction = exports.PollingFunction = /*#__PURE__*/function () {
|
|
|
68
68
|
_context.next = 3;
|
|
69
69
|
break;
|
|
70
70
|
}
|
|
71
|
-
return _context.abrupt("return", this.fail(new _errors.PollingError('pollingMaxAttemptsExceeded',
|
|
71
|
+
return _context.abrupt("return", this.fail(new _errors.PollingError('pollingMaxAttemptsExceeded', {
|
|
72
|
+
attempts: this.attempt
|
|
73
|
+
})));
|
|
72
74
|
case 3:
|
|
73
75
|
_context.prev = 3;
|
|
74
76
|
// executor must explicitly call this.next() for triggering next iteration (pull)
|
|
@@ -86,7 +88,9 @@ var PollingFunction = exports.PollingFunction = /*#__PURE__*/function () {
|
|
|
86
88
|
_context.next = 11;
|
|
87
89
|
break;
|
|
88
90
|
}
|
|
89
|
-
return _context.abrupt("return", this.fail(new _errors.PollingError('pollingMaxAttemptsExceeded',
|
|
91
|
+
return _context.abrupt("return", this.fail(new _errors.PollingError('pollingMaxAttemptsExceeded', {
|
|
92
|
+
attempts: this.attempt
|
|
93
|
+
})));
|
|
90
94
|
case 11:
|
|
91
95
|
this.poll_intervalMs = this.getIntervalMsForIteration(this.attempt);
|
|
92
96
|
this.attempt++;
|
|
@@ -16,14 +16,12 @@ function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0,
|
|
|
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
18
|
function RequestError(reason, metadata, innerError) {
|
|
19
|
-
var _this;
|
|
20
19
|
(0, _classCallCheck2.default)(this, RequestError);
|
|
21
|
-
|
|
22
|
-
_this.reason = reason;
|
|
23
|
-
_this.metadata = metadata;
|
|
24
|
-
_this.innerError = innerError;
|
|
25
|
-
return _this;
|
|
20
|
+
return _callSuper(this, RequestError, [reason, metadata, innerError]);
|
|
26
21
|
}
|
|
22
|
+
|
|
23
|
+
// TODO: Deprecate this getter https://product-fabric.atlassian.net/browse/CXP-4665
|
|
24
|
+
/** Will be deprecated. Use the properties `reason` and `metadata` instead */
|
|
27
25
|
(0, _inherits2.default)(RequestError, _BaseMediaClientError);
|
|
28
26
|
return (0, _createClass2.default)(RequestError, [{
|
|
29
27
|
key: "attributes",
|
|
@@ -33,6 +33,10 @@ var _authQueryParameters = require("../../models/auth-query-parameters");
|
|
|
33
33
|
var _errors = require("./errors");
|
|
34
34
|
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; }
|
|
35
35
|
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) { (0, _defineProperty2.default)(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; }
|
|
36
|
+
var getStatusCode = function getStatusCode(error) {
|
|
37
|
+
var _error$metadata;
|
|
38
|
+
return (0, _errors.isRequestError)(error) && ((_error$metadata = error.metadata) === null || _error$metadata === void 0 ? void 0 : _error$metadata.statusCode) && error.metadata.statusCode;
|
|
39
|
+
};
|
|
36
40
|
function waitPromise(timeout) {
|
|
37
41
|
return new Promise(function (resolve) {
|
|
38
42
|
return setTimeout(resolve, timeout);
|
|
@@ -47,7 +51,8 @@ function isFetchNetworkError(err) {
|
|
|
47
51
|
return err instanceof TypeError;
|
|
48
52
|
}
|
|
49
53
|
function isRateLimitedError(error) {
|
|
50
|
-
|
|
54
|
+
var statusCode = error && getStatusCode(error);
|
|
55
|
+
return statusCode === 429 || !!error && !!error.message && error.message.includes('429');
|
|
51
56
|
}
|
|
52
57
|
var extendTraceContext = exports.extendTraceContext = function extendTraceContext(traceContext) {
|
|
53
58
|
return traceContext ? _objectSpread(_objectSpread({}, traceContext), {}, {
|
|
@@ -160,8 +165,8 @@ function createMapResponseToBlob(metadata) {
|
|
|
160
165
|
}();
|
|
161
166
|
}
|
|
162
167
|
var defaultShouldRetryError = exports.defaultShouldRetryError = function defaultShouldRetryError(err) {
|
|
163
|
-
var
|
|
164
|
-
return isFetchNetworkError(err) || (
|
|
168
|
+
var statusCode = getStatusCode(err);
|
|
169
|
+
return isFetchNetworkError(err) || (statusCode ? statusCode >= 500 : false);
|
|
165
170
|
};
|
|
166
171
|
var DEFAULT_RETRY_OPTIONS = exports.DEFAULT_RETRY_OPTIONS = {
|
|
167
172
|
startTimeoutInMs: 1000,
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import { BaseMediaClientError } from '../../models/errors';
|
|
2
2
|
export class FileFetcherError extends BaseMediaClientError {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
this.
|
|
3
|
+
// Legacy Attribute. Should be removed
|
|
4
|
+
|
|
5
|
+
constructor(reason, metadata) {
|
|
6
|
+
super(reason, metadata, undefined);
|
|
7
|
+
this.id = metadata.id;
|
|
8
8
|
}
|
|
9
|
+
|
|
10
|
+
// TODO: Deprecate this getter https://product-fabric.atlassian.net/browse/CXP-4665
|
|
11
|
+
/** Will be deprecated. Use the properties `reason` and `metadata` instead */
|
|
9
12
|
get attributes() {
|
|
10
13
|
const {
|
|
11
14
|
reason,
|
|
12
|
-
id,
|
|
13
15
|
metadata: {
|
|
16
|
+
id,
|
|
14
17
|
collectionName,
|
|
15
18
|
occurrenceKey,
|
|
16
19
|
traceContext
|
|
17
|
-
}
|
|
20
|
+
}
|
|
18
21
|
} = this;
|
|
19
22
|
return {
|
|
20
23
|
reason,
|
|
@@ -27,36 +27,27 @@ import { isEmptyFile } from '../../utils/detectEmptyFile';
|
|
|
27
27
|
import { mediaStore } from '@atlaskit/media-state';
|
|
28
28
|
import { createCopyIntentRegisterationBatcher } from '../../utils/createCopyIntentRegisterationBatcher';
|
|
29
29
|
import { defaultShouldRetryError } from '../../utils/request/helpers';
|
|
30
|
+
import { isCommonMediaClientError, CommonMediaClientError, fromCommonMediaClientError } from '../../models/errors';
|
|
30
31
|
export { isFileFetcherError, FileFetcherError } from './error';
|
|
31
32
|
const isCopySourceFileWithToken = token => !!token.authProvider;
|
|
32
33
|
const isCopyDestinationWithToken = token => !!token.authProvider;
|
|
33
34
|
export class FileFetcherImpl {
|
|
34
35
|
constructor(mediaApi, store = mediaStore) {
|
|
35
36
|
_defineProperty(this, "getErrorFileState", (error, id, occurrenceKey) => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
occurrenceKey,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
reason: error === null || error === void 0 ? void 0 : error.reason,
|
|
51
|
-
details: {
|
|
52
|
-
...attributes,
|
|
53
|
-
...((metadata === null || metadata === void 0 ? void 0 : metadata.traceContext) && {
|
|
54
|
-
metadata
|
|
55
|
-
})
|
|
56
|
-
},
|
|
57
|
-
occurrenceKey,
|
|
58
|
-
message: error === null || error === void 0 ? void 0 : error.message
|
|
59
|
-
};
|
|
37
|
+
if (isCommonMediaClientError(error)) {
|
|
38
|
+
return fromCommonMediaClientError(id, occurrenceKey, error);
|
|
39
|
+
}
|
|
40
|
+
// ________________________________________________
|
|
41
|
+
// Legacy serializers
|
|
42
|
+
// We need to revisit all the incoming error types and ensure all the "reason" values are known
|
|
43
|
+
// We need to change the input error: any for a known type.
|
|
44
|
+
if (typeof error === 'string') {
|
|
45
|
+
const err = new CommonMediaClientError(error);
|
|
46
|
+
return fromCommonMediaClientError(id, occurrenceKey, err);
|
|
47
|
+
} else {
|
|
48
|
+
const err = new CommonMediaClientError((error === null || error === void 0 ? void 0 : error.reason) || 'unknown', error === null || error === void 0 ? void 0 : error.metadata, error === null || error === void 0 ? void 0 : error.innerError);
|
|
49
|
+
return fromCommonMediaClientError(id, occurrenceKey, err);
|
|
50
|
+
}
|
|
60
51
|
});
|
|
61
52
|
_defineProperty(this, "setFileState", (id, fileState) => {
|
|
62
53
|
this.store.setState(state => {
|
|
@@ -64,27 +55,36 @@ export class FileFetcherImpl {
|
|
|
64
55
|
});
|
|
65
56
|
});
|
|
66
57
|
// TODO: ----- ADD TICKET TO PASS TRACE ID to this.dataloader.load
|
|
67
|
-
_defineProperty(this, "createDownloadFileStream", (id, collectionName, occurrenceKey, includeHashForDuplicateFiles) => {
|
|
58
|
+
_defineProperty(this, "createDownloadFileStream", (id, collectionName, occurrenceKey, includeHashForDuplicateFiles, forceRefresh) => {
|
|
68
59
|
const subject = createMediaSubject();
|
|
69
60
|
const poll = new PollingFunction();
|
|
70
61
|
|
|
71
62
|
// ensure subject errors if polling exceeds max iterations or uncaught exception in executor
|
|
72
63
|
poll.onError = error => subject.error(error);
|
|
73
64
|
poll.execute(async () => {
|
|
65
|
+
if (forceRefresh) {
|
|
66
|
+
this.dataloader.clear({
|
|
67
|
+
id,
|
|
68
|
+
collectionName,
|
|
69
|
+
includeHashForDuplicateFiles
|
|
70
|
+
});
|
|
71
|
+
}
|
|
74
72
|
const response = await this.dataloader.load({
|
|
75
73
|
id,
|
|
76
74
|
collectionName,
|
|
77
75
|
includeHashForDuplicateFiles
|
|
78
76
|
});
|
|
79
77
|
if (isNotFoundMediaItemDetails(response)) {
|
|
80
|
-
throw new FileFetcherError('emptyItems',
|
|
78
|
+
throw new FileFetcherError('emptyItems', {
|
|
79
|
+
id,
|
|
81
80
|
collectionName,
|
|
82
81
|
occurrenceKey,
|
|
83
82
|
traceContext: response.metadataTraceContext
|
|
84
83
|
});
|
|
85
84
|
}
|
|
86
85
|
if (isEmptyFile(response)) {
|
|
87
|
-
throw new FileFetcherError('zeroVersionFile',
|
|
86
|
+
throw new FileFetcherError('zeroVersionFile', {
|
|
87
|
+
id,
|
|
88
88
|
collectionName,
|
|
89
89
|
occurrenceKey,
|
|
90
90
|
traceContext: response.metadataTraceContext
|
|
@@ -149,38 +149,26 @@ export class FileFetcherImpl {
|
|
|
149
149
|
const {
|
|
150
150
|
collectionName,
|
|
151
151
|
occurrenceKey,
|
|
152
|
-
includeHashForDuplicateFiles
|
|
152
|
+
includeHashForDuplicateFiles,
|
|
153
|
+
forceRefresh
|
|
153
154
|
} = options;
|
|
154
155
|
if (!isValidId(id)) {
|
|
155
|
-
var _err$attributes;
|
|
156
156
|
const subject = createMediaSubject();
|
|
157
|
-
const err = new FileFetcherError('invalidFileId',
|
|
157
|
+
const err = new FileFetcherError('invalidFileId', {
|
|
158
|
+
id,
|
|
158
159
|
collectionName,
|
|
159
160
|
occurrenceKey
|
|
160
161
|
});
|
|
161
|
-
const
|
|
162
|
-
metadata,
|
|
163
|
-
...attributes
|
|
164
|
-
} = (_err$attributes = err === null || err === void 0 ? void 0 : err.attributes) !== null && _err$attributes !== void 0 ? _err$attributes : {};
|
|
165
|
-
const errorFileState = {
|
|
166
|
-
status: 'error',
|
|
167
|
-
id,
|
|
168
|
-
reason: err === null || err === void 0 ? void 0 : err.reason,
|
|
169
|
-
message: err === null || err === void 0 ? void 0 : err.message,
|
|
170
|
-
occurrenceKey,
|
|
171
|
-
details: {
|
|
172
|
-
...attributes,
|
|
173
|
-
...((metadata === null || metadata === void 0 ? void 0 : metadata.traceContext) && {
|
|
174
|
-
metadata
|
|
175
|
-
})
|
|
176
|
-
}
|
|
177
|
-
};
|
|
162
|
+
const errorFileState = this.getErrorFileState(err, id, occurrenceKey);
|
|
178
163
|
subject.error(err);
|
|
179
164
|
this.setFileState(id, errorFileState);
|
|
180
165
|
return fromObservable(subject);
|
|
181
166
|
}
|
|
167
|
+
if (forceRefresh) {
|
|
168
|
+
getFileStreamsCache().remove(id);
|
|
169
|
+
}
|
|
182
170
|
return fromObservable(getFileStreamsCache().getOrInsert(id, () => {
|
|
183
|
-
const subject = this.createDownloadFileStream(id, collectionName, undefined, includeHashForDuplicateFiles);
|
|
171
|
+
const subject = this.createDownloadFileStream(id, collectionName, undefined, includeHashForDuplicateFiles, forceRefresh);
|
|
184
172
|
subject.subscribe({
|
|
185
173
|
next: fileState => {
|
|
186
174
|
this.setFileState(id, fileState);
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { BaseMediaClientError } from '../../models/errors';
|
|
2
2
|
export class MediaStoreError extends BaseMediaClientError {
|
|
3
3
|
constructor(reason, innerError) {
|
|
4
|
-
super(reason);
|
|
5
|
-
this.reason = reason;
|
|
6
|
-
this.innerError = innerError;
|
|
4
|
+
super(reason, undefined, innerError);
|
|
7
5
|
}
|
|
6
|
+
|
|
7
|
+
// TODO: Deprecate this getter https://product-fabric.atlassian.net/browse/CXP-4665
|
|
8
|
+
/** Will be deprecated. Use the properties `reason` and `metadata` instead */
|
|
8
9
|
get attributes() {
|
|
9
10
|
const {
|
|
10
11
|
reason,
|
package/dist/es2019/index.js
CHANGED
|
@@ -2,8 +2,8 @@ export { MediaStore, MediaStoreError, isMediaStoreError, getMediaEnvironment, ge
|
|
|
2
2
|
export { UploadController } from './upload-controller';
|
|
3
3
|
export { isPreviewableType } from './models/media';
|
|
4
4
|
export { getArtifactUrl } from './models/artifacts';
|
|
5
|
-
export { isMediaClientError, getMediaClientErrorReason } from './models/errors';
|
|
6
|
-
export { isUploadingFileState, isProcessingFileState, isProcessedFileState, isErrorFileState, isPreviewableFileState, isFinalFileState, isImageRepresentationReady, mapMediaFileToFileState, mapMediaItemToFileState } from './models/file-state';
|
|
5
|
+
export { isMediaClientError, getMediaClientErrorReason, isCommonMediaClientError, toCommonMediaClientError } from './models/errors';
|
|
6
|
+
export { isUploadingFileState, isProcessingFileState, isProcessedFileState, isErrorFileState, isPreviewableFileState, isFinalFileState, isImageRepresentationReady, isNonErrorFinalFileState, mapMediaFileToFileState, mapMediaItemToFileState } from './models/file-state';
|
|
7
7
|
export { uploadFile } from './uploader';
|
|
8
8
|
export { request, RequestError, isRequestError, isRateLimitedError, createRequestErrorReason } from './utils/request';
|
|
9
9
|
export { isAbortedRequestError, createUrl } from './utils/request/helpers';
|
|
@@ -3,12 +3,16 @@ export { isMediaClientError, getMediaClientErrorReason } from './helpers';
|
|
|
3
3
|
/**
|
|
4
4
|
* Base class for media errors
|
|
5
5
|
*/
|
|
6
|
-
export class BaseMediaClientError extends Error
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
export class BaseMediaClientError extends Error
|
|
7
|
+
// TODO: Deprecate attributes getter https://product-fabric.atlassian.net/browse/CXP-4665
|
|
8
|
+
{
|
|
9
|
+
constructor(reason, metadata, innerError) {
|
|
10
|
+
super(reason);
|
|
9
11
|
|
|
10
12
|
// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html#support-for-newtarget
|
|
11
|
-
this.
|
|
13
|
+
this.reason = reason;
|
|
14
|
+
this.metadata = metadata;
|
|
15
|
+
this.innerError = innerError;
|
|
12
16
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
13
17
|
|
|
14
18
|
// https://v8.dev/docs/stack-trace-api
|
|
@@ -16,4 +20,57 @@ export class BaseMediaClientError extends Error {
|
|
|
16
20
|
Error.captureStackTrace(this, new.target);
|
|
17
21
|
}
|
|
18
22
|
}
|
|
19
|
-
|
|
23
|
+
|
|
24
|
+
// TODO: Deprecate attributes getter https://product-fabric.atlassian.net/browse/CXP-4665
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// The only reason why this class exists is because BaseMediaClientError is abstract class, so it can't be used to deserialize ErrorFileState. We can refactor and simplify this later.
|
|
28
|
+
/** Generic Media Client Erorr. All errors extending BaseMediaClientError match CommonMediaClientError attributes. Used to deserialize ErrorFileState */
|
|
29
|
+
export class CommonMediaClientError extends BaseMediaClientError {
|
|
30
|
+
constructor(reason, metadata, innerError) {
|
|
31
|
+
super(reason, metadata, innerError);
|
|
32
|
+
}
|
|
33
|
+
get attributes() {
|
|
34
|
+
return {
|
|
35
|
+
reason: this.reason
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export function isCommonMediaClientError(error) {
|
|
40
|
+
if (!error) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
// Check if the error is an instance of Error
|
|
44
|
+
if (error instanceof CommonMediaClientError) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
return typeof error.reason === 'string' && ('metadata' in error || error.metadata === undefined) && ('innerError' in error || error.innerError === undefined);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Deserializer ErrorFileState -> CommonMediaClientError */
|
|
51
|
+
export const toCommonMediaClientError = errorFileState => {
|
|
52
|
+
var _errorFileState$detai;
|
|
53
|
+
const error = (_errorFileState$detai = errorFileState.details) === null || _errorFileState$detai === void 0 ? void 0 : _errorFileState$detai.error;
|
|
54
|
+
return new CommonMediaClientError((error === null || error === void 0 ? void 0 : error.reason) || 'unknown-reason', error.metadata, error.innerError);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/** Serializer CommonMediaClientError -> ErrorFileState */
|
|
58
|
+
export const fromCommonMediaClientError = (id, occurrenceKey, error) => {
|
|
59
|
+
return {
|
|
60
|
+
status: 'error',
|
|
61
|
+
id,
|
|
62
|
+
occurrenceKey,
|
|
63
|
+
reason: error.reason,
|
|
64
|
+
details: {
|
|
65
|
+
/** Use this attr to translate back into CommonMediaClientError (toCommonMediaClientError) */
|
|
66
|
+
error: {
|
|
67
|
+
reason: error === null || error === void 0 ? void 0 : error.reason,
|
|
68
|
+
metadata: error === null || error === void 0 ? void 0 : error.metadata,
|
|
69
|
+
innerError: error === null || error === void 0 ? void 0 : error.innerError
|
|
70
|
+
},
|
|
71
|
+
// Legacy details
|
|
72
|
+
...(error === null || error === void 0 ? void 0 : error.attributes)
|
|
73
|
+
},
|
|
74
|
+
message: error === null || error === void 0 ? void 0 : error.message
|
|
75
|
+
};
|
|
76
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -4,6 +4,7 @@ export const isProcessedFileState = fileState => fileState.status === 'processed
|
|
|
4
4
|
export const isErrorFileState = fileState => fileState.status === 'error';
|
|
5
5
|
export const isPreviewableFileState = fileState => !isErrorFileState(fileState) && !!fileState.preview;
|
|
6
6
|
export const isFinalFileState = fileState => ['processed', 'failed-processing', 'error'].includes(fileState.status);
|
|
7
|
+
export const isNonErrorFinalFileState = fileState => ['processed', 'failed-processing'].includes(fileState.status);
|
|
7
8
|
export const isImageRepresentationReady = fileState => {
|
|
8
9
|
switch (fileState.status) {
|
|
9
10
|
case 'processing':
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import { BaseMediaClientError } from '../models/errors';
|
|
2
2
|
export class UploaderError extends BaseMediaClientError {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
this.
|
|
3
|
+
// Legacy Attribute. Should be removed
|
|
4
|
+
|
|
5
|
+
constructor(reason, metadata) {
|
|
6
|
+
super(reason, metadata, undefined);
|
|
7
|
+
this.id = metadata.id;
|
|
8
8
|
}
|
|
9
|
+
|
|
10
|
+
// TODO: Deprecate this getter https://product-fabric.atlassian.net/browse/CXP-4665
|
|
11
|
+
/** Will be deprecated. Use the properties `reason` and `metadata` instead */
|
|
9
12
|
get attributes() {
|
|
10
13
|
const {
|
|
11
14
|
reason,
|
|
12
|
-
id,
|
|
13
15
|
metadata: {
|
|
16
|
+
id,
|
|
14
17
|
collectionName,
|
|
15
18
|
occurrenceKey
|
|
16
|
-
}
|
|
19
|
+
}
|
|
17
20
|
} = this;
|
|
18
21
|
return {
|
|
19
22
|
reason,
|
|
@@ -70,7 +70,8 @@ export const uploadFile = (file, store, uploadableFileUpfrontIds, callbacks, tra
|
|
|
70
70
|
}
|
|
71
71
|
} catch (err) {
|
|
72
72
|
if (err instanceof Error && err.message === fileSizeError) {
|
|
73
|
-
callbacks === null || callbacks === void 0 ? void 0 : callbacks.onUploadFinish(new UploaderError(err.message,
|
|
73
|
+
callbacks === null || callbacks === void 0 ? void 0 : callbacks.onUploadFinish(new UploaderError(err.message, {
|
|
74
|
+
id,
|
|
74
75
|
collectionName: collection,
|
|
75
76
|
occurrenceKey: occurrenceKey
|
|
76
77
|
}));
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import { BaseMediaClientError } from '../../models/errors';
|
|
2
2
|
export class MobileUploadError extends BaseMediaClientError {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
this.
|
|
3
|
+
// Legacy Attribute. Should be removed
|
|
4
|
+
|
|
5
|
+
constructor(reason, metadata) {
|
|
6
|
+
super(reason, metadata, undefined);
|
|
7
|
+
this.id = metadata.id;
|
|
8
8
|
}
|
|
9
|
+
|
|
10
|
+
// TODO: Deprecate this getter https://product-fabric.atlassian.net/browse/CXP-4665
|
|
11
|
+
/** Will be deprecated. Use the properties `reason` and `metadata` instead */
|
|
9
12
|
get attributes() {
|
|
10
13
|
const {
|
|
11
14
|
reason,
|
|
12
|
-
id,
|
|
13
15
|
metadata: {
|
|
16
|
+
id,
|
|
14
17
|
collectionName,
|
|
15
18
|
occurrenceKey,
|
|
16
19
|
traceContext
|
|
17
|
-
}
|
|
20
|
+
}
|
|
18
21
|
} = this;
|
|
19
22
|
return {
|
|
20
23
|
reason,
|
|
@@ -24,14 +24,16 @@ export const createMobileDownloadFileStream = (dataloader, id, collectionName, o
|
|
|
24
24
|
collectionName
|
|
25
25
|
});
|
|
26
26
|
if (isNotFoundMediaItemDetails(response)) {
|
|
27
|
-
throw new MobileUploadError('emptyItems',
|
|
27
|
+
throw new MobileUploadError('emptyItems', {
|
|
28
|
+
id,
|
|
28
29
|
collectionName,
|
|
29
30
|
occurrenceKey,
|
|
30
31
|
traceContext: response.metadataTraceContext
|
|
31
32
|
});
|
|
32
33
|
}
|
|
33
34
|
if (isEmptyFile(response)) {
|
|
34
|
-
throw new MobileUploadError('zeroVersionFile',
|
|
35
|
+
throw new MobileUploadError('zeroVersionFile', {
|
|
36
|
+
id,
|
|
35
37
|
collectionName,
|
|
36
38
|
occurrenceKey,
|
|
37
39
|
traceContext: response.metadataTraceContext
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { BaseMediaClientError } from '../../models/errors';
|
|
2
2
|
export class PollingError extends BaseMediaClientError {
|
|
3
|
-
constructor(reason,
|
|
4
|
-
super(reason);
|
|
5
|
-
this.reason = reason;
|
|
6
|
-
this.attempts = attempts;
|
|
3
|
+
constructor(reason, metadata) {
|
|
4
|
+
super(reason, metadata, undefined);
|
|
7
5
|
}
|
|
6
|
+
|
|
7
|
+
// TODO: Deprecate this getter https://product-fabric.atlassian.net/browse/CXP-4665
|
|
8
|
+
/** Will be deprecated. Use the properties `reason` and `metadata` instead */
|
|
8
9
|
get attributes() {
|
|
9
10
|
const {
|
|
10
11
|
reason,
|
|
11
|
-
|
|
12
|
+
metadata: {
|
|
13
|
+
attempts
|
|
14
|
+
}
|
|
12
15
|
} = this;
|
|
13
16
|
return {
|
|
14
17
|
reason,
|
|
@@ -38,7 +38,9 @@ export class PollingFunction {
|
|
|
38
38
|
} = this.options;
|
|
39
39
|
if (poll_maxAttempts === 0) {
|
|
40
40
|
// hard kill, polling disabled
|
|
41
|
-
return this.fail(new PollingError('pollingMaxAttemptsExceeded',
|
|
41
|
+
return this.fail(new PollingError('pollingMaxAttemptsExceeded', {
|
|
42
|
+
attempts: this.attempt
|
|
43
|
+
}));
|
|
42
44
|
}
|
|
43
45
|
try {
|
|
44
46
|
// executor must explicitly call this.next() for triggering next iteration (pull)
|
|
@@ -49,7 +51,9 @@ export class PollingFunction {
|
|
|
49
51
|
}
|
|
50
52
|
if (this.attempt >= poll_maxAttempts) {
|
|
51
53
|
// max iterations exceeded, let the consumer know
|
|
52
|
-
return this.fail(new PollingError('pollingMaxAttemptsExceeded',
|
|
54
|
+
return this.fail(new PollingError('pollingMaxAttemptsExceeded', {
|
|
55
|
+
attempts: this.attempt
|
|
56
|
+
}));
|
|
53
57
|
}
|
|
54
58
|
this.poll_intervalMs = this.getIntervalMsForIteration(this.attempt);
|
|
55
59
|
this.attempt++;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { BaseMediaClientError } from '../../models/errors';
|
|
2
2
|
export class RequestError extends BaseMediaClientError {
|
|
3
3
|
constructor(reason, metadata, innerError) {
|
|
4
|
-
super(reason);
|
|
5
|
-
this.reason = reason;
|
|
6
|
-
this.metadata = metadata;
|
|
7
|
-
this.innerError = innerError;
|
|
4
|
+
super(reason, metadata, innerError);
|
|
8
5
|
}
|
|
6
|
+
|
|
7
|
+
// TODO: Deprecate this getter https://product-fabric.atlassian.net/browse/CXP-4665
|
|
8
|
+
/** Will be deprecated. Use the properties `reason` and `metadata` instead */
|
|
9
9
|
get attributes() {
|
|
10
10
|
const {
|
|
11
11
|
reason,
|
|
@@ -2,6 +2,10 @@ import { isClientBasedAuth } from '@atlaskit/media-core';
|
|
|
2
2
|
import { getRandomHex } from '@atlaskit/media-common';
|
|
3
3
|
import { mapAuthToQueryParameters } from '../../models/auth-query-parameters';
|
|
4
4
|
import { RequestError, isRequestError } from './errors';
|
|
5
|
+
const getStatusCode = error => {
|
|
6
|
+
var _error$metadata;
|
|
7
|
+
return isRequestError(error) && ((_error$metadata = error.metadata) === null || _error$metadata === void 0 ? void 0 : _error$metadata.statusCode) && error.metadata.statusCode;
|
|
8
|
+
};
|
|
5
9
|
export function waitPromise(timeout) {
|
|
6
10
|
return new Promise(resolve => setTimeout(resolve, timeout));
|
|
7
11
|
}
|
|
@@ -14,7 +18,8 @@ export function isFetchNetworkError(err) {
|
|
|
14
18
|
return err instanceof TypeError;
|
|
15
19
|
}
|
|
16
20
|
export function isRateLimitedError(error) {
|
|
17
|
-
|
|
21
|
+
const statusCode = error && getStatusCode(error);
|
|
22
|
+
return statusCode === 429 || !!error && !!error.message && error.message.includes('429');
|
|
18
23
|
}
|
|
19
24
|
export const extendTraceContext = traceContext => traceContext ? {
|
|
20
25
|
...traceContext,
|
|
@@ -101,8 +106,8 @@ export function createMapResponseToBlob(metadata) {
|
|
|
101
106
|
};
|
|
102
107
|
}
|
|
103
108
|
export const defaultShouldRetryError = err => {
|
|
104
|
-
|
|
105
|
-
return isFetchNetworkError(err) ||
|
|
109
|
+
const statusCode = getStatusCode(err);
|
|
110
|
+
return isFetchNetworkError(err) || (statusCode ? statusCode >= 500 : false);
|
|
106
111
|
};
|
|
107
112
|
export const DEFAULT_RETRY_OPTIONS = {
|
|
108
113
|
startTimeoutInMs: 1000,
|
|
@@ -10,26 +10,28 @@ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstruct
|
|
|
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
|
-
|
|
13
|
+
// Legacy Attribute. Should be removed
|
|
14
|
+
|
|
15
|
+
function FileFetcherError(reason, metadata) {
|
|
14
16
|
var _this;
|
|
15
17
|
_classCallCheck(this, FileFetcherError);
|
|
16
|
-
_this = _callSuper(this, FileFetcherError, [reason]);
|
|
17
|
-
_this.
|
|
18
|
-
_this.id = id;
|
|
19
|
-
_this.metadata = metadata;
|
|
18
|
+
_this = _callSuper(this, FileFetcherError, [reason, metadata, undefined]);
|
|
19
|
+
_this.id = metadata.id;
|
|
20
20
|
return _this;
|
|
21
21
|
}
|
|
22
|
+
|
|
23
|
+
// TODO: Deprecate this getter https://product-fabric.atlassian.net/browse/CXP-4665
|
|
24
|
+
/** Will be deprecated. Use the properties `reason` and `metadata` instead */
|
|
22
25
|
_inherits(FileFetcherError, _BaseMediaClientError);
|
|
23
26
|
return _createClass(FileFetcherError, [{
|
|
24
27
|
key: "attributes",
|
|
25
28
|
get: function get() {
|
|
26
29
|
var reason = this.reason,
|
|
27
|
-
id = this.id,
|
|
28
30
|
_this$metadata = this.metadata,
|
|
29
|
-
|
|
30
|
-
collectionName = _this$
|
|
31
|
-
occurrenceKey = _this$
|
|
32
|
-
traceContext = _this$
|
|
31
|
+
id = _this$metadata.id,
|
|
32
|
+
collectionName = _this$metadata.collectionName,
|
|
33
|
+
occurrenceKey = _this$metadata.occurrenceKey,
|
|
34
|
+
traceContext = _this$metadata.traceContext;
|
|
33
35
|
return _objectSpread({
|
|
34
36
|
reason: reason,
|
|
35
37
|
id: id,
|