@uploadcare/upload-client 6.11.0 → 6.12.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/dist/cjs/index.browser.cjs +36 -23
- package/dist/cjs/index.browser.d.cts +18 -7
- package/dist/cjs/index.node.cjs +35 -22
- package/dist/cjs/index.node.d.cts +18 -7
- package/dist/cjs/index.react-native.cjs +36 -23
- package/dist/cjs/index.react-native.d.cts +18 -7
- package/dist/esm/index.browser.d.mts +18 -7
- package/dist/esm/index.browser.mjs +33 -24
- package/dist/esm/index.node.d.mts +18 -7
- package/dist/esm/index.node.mjs +32 -23
- package/dist/esm/index.react-native.d.mts +18 -7
- package/dist/esm/index.react-native.mjs +33 -24
- package/dist/index.d.ts +18 -7
- package/package.json +3 -3
|
@@ -91,13 +91,16 @@ function retrier(fn, options = defaultOptions) {
|
|
|
91
91
|
return runAttempt(fn);
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
class
|
|
94
|
+
class UploadcareError extends Error {
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
class NetworkError extends UploadcareError {
|
|
95
98
|
originalProgressEvent;
|
|
96
99
|
constructor(progressEvent) {
|
|
97
100
|
super();
|
|
98
|
-
this.name = '
|
|
101
|
+
this.name = 'NetworkError';
|
|
99
102
|
this.message = 'Network error';
|
|
100
|
-
Object.setPrototypeOf(this,
|
|
103
|
+
Object.setPrototypeOf(this, NetworkError.prototype);
|
|
101
104
|
this.originalProgressEvent = progressEvent;
|
|
102
105
|
}
|
|
103
106
|
}
|
|
@@ -113,10 +116,11 @@ const onCancel = (signal, callback) => {
|
|
|
113
116
|
}
|
|
114
117
|
};
|
|
115
118
|
|
|
116
|
-
class CancelError extends
|
|
119
|
+
class CancelError extends UploadcareError {
|
|
117
120
|
isCancel = true;
|
|
118
121
|
constructor(message = 'Request canceled') {
|
|
119
122
|
super(message);
|
|
123
|
+
this.name = 'CancelError';
|
|
120
124
|
Object.setPrototypeOf(this, CancelError.prototype);
|
|
121
125
|
}
|
|
122
126
|
}
|
|
@@ -249,7 +253,7 @@ const request = ({ method, url, data, headers = {}, signal, onProgress }) => new
|
|
|
249
253
|
if (aborted)
|
|
250
254
|
return;
|
|
251
255
|
// only triggers if the request couldn't be made at all
|
|
252
|
-
reject(new
|
|
256
|
+
reject(new NetworkError(progressEvent));
|
|
253
257
|
};
|
|
254
258
|
if (onProgress && typeof onProgress === 'function') {
|
|
255
259
|
xhr.upload.onprogress = (event) => {
|
|
@@ -348,21 +352,20 @@ function buildFormData(options) {
|
|
|
348
352
|
return formData;
|
|
349
353
|
}
|
|
350
354
|
|
|
351
|
-
class
|
|
352
|
-
isCancel;
|
|
355
|
+
class UploadError extends UploadcareError {
|
|
353
356
|
code;
|
|
354
357
|
request;
|
|
355
358
|
response;
|
|
356
359
|
headers;
|
|
357
360
|
constructor(message, code, request, response, headers) {
|
|
358
361
|
super();
|
|
359
|
-
this.name = '
|
|
362
|
+
this.name = 'UploadError';
|
|
360
363
|
this.message = message;
|
|
361
364
|
this.code = code;
|
|
362
365
|
this.request = request;
|
|
363
366
|
this.response = response;
|
|
364
367
|
this.headers = headers;
|
|
365
|
-
Object.setPrototypeOf(this,
|
|
368
|
+
Object.setPrototypeOf(this, UploadError.prototype);
|
|
366
369
|
}
|
|
367
370
|
}
|
|
368
371
|
|
|
@@ -397,7 +400,7 @@ const getUrl = (base, path, query) => {
|
|
|
397
400
|
return url.toString();
|
|
398
401
|
};
|
|
399
402
|
|
|
400
|
-
var version = '6.
|
|
403
|
+
var version = '6.12.0';
|
|
401
404
|
|
|
402
405
|
const LIBRARY_NAME = 'UploadcareUploadClient';
|
|
403
406
|
const LIBRARY_VERSION = version;
|
|
@@ -431,7 +434,7 @@ function retryIfFailed(fn, options) {
|
|
|
431
434
|
attempt < retryThrottledRequestMaxTimes) {
|
|
432
435
|
return retry(getTimeoutFromThrottledRequest(error));
|
|
433
436
|
}
|
|
434
|
-
if (error instanceof
|
|
437
|
+
if (error instanceof NetworkError &&
|
|
435
438
|
attempt < retryNetworkErrorMaxTimes) {
|
|
436
439
|
return retry((attempt + 1) * DEFAULT_NETWORK_ERROR_TIMEOUT);
|
|
437
440
|
}
|
|
@@ -499,7 +502,7 @@ function base(file, { publicKey, fileName, contentType, baseURL = defaultSetting
|
|
|
499
502
|
}).then(({ data, headers, request }) => {
|
|
500
503
|
const response = camelizeKeys(JSON.parse(data));
|
|
501
504
|
if ('error' in response) {
|
|
502
|
-
throw new
|
|
505
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
503
506
|
}
|
|
504
507
|
else {
|
|
505
508
|
return response;
|
|
@@ -536,7 +539,7 @@ function fromUrl(sourceUrl, { publicKey, baseURL = defaultSettings.baseURL, stor
|
|
|
536
539
|
}).then(({ data, headers, request }) => {
|
|
537
540
|
const response = camelizeKeys(JSON.parse(data));
|
|
538
541
|
if ('error' in response) {
|
|
539
|
-
throw new
|
|
542
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
540
543
|
}
|
|
541
544
|
else {
|
|
542
545
|
return response;
|
|
@@ -576,7 +579,7 @@ function fromUrlStatus(token, { publicKey, baseURL = defaultSettings.baseURL, si
|
|
|
576
579
|
}).then(({ data, headers, request }) => {
|
|
577
580
|
const response = camelizeKeys(JSON.parse(data));
|
|
578
581
|
if ('error' in response && !isErrorResponse(response)) {
|
|
579
|
-
throw new
|
|
582
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
580
583
|
}
|
|
581
584
|
else {
|
|
582
585
|
return response;
|
|
@@ -604,7 +607,7 @@ function group(uuids, { publicKey, baseURL = defaultSettings.baseURL, jsonpCallb
|
|
|
604
607
|
}).then(({ data, headers, request }) => {
|
|
605
608
|
const response = camelizeKeys(JSON.parse(data));
|
|
606
609
|
if ('error' in response) {
|
|
607
|
-
throw new
|
|
610
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
608
611
|
}
|
|
609
612
|
else {
|
|
610
613
|
return response;
|
|
@@ -629,7 +632,7 @@ function groupInfo(id, { publicKey, baseURL = defaultSettings.baseURL, signal, s
|
|
|
629
632
|
}).then(({ data, headers, request }) => {
|
|
630
633
|
const response = camelizeKeys(JSON.parse(data));
|
|
631
634
|
if ('error' in response) {
|
|
632
|
-
throw new
|
|
635
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
633
636
|
}
|
|
634
637
|
else {
|
|
635
638
|
return response;
|
|
@@ -654,7 +657,7 @@ function info(uuid, { publicKey, baseURL = defaultSettings.baseURL, signal, sour
|
|
|
654
657
|
}).then(({ data, headers, request }) => {
|
|
655
658
|
const response = camelizeKeys(JSON.parse(data));
|
|
656
659
|
if ('error' in response) {
|
|
657
|
-
throw new
|
|
660
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
658
661
|
}
|
|
659
662
|
else {
|
|
660
663
|
return response;
|
|
@@ -686,7 +689,7 @@ function multipartStart(size, { publicKey, contentType, fileName, multipartChunk
|
|
|
686
689
|
}).then(({ data, headers, request }) => {
|
|
687
690
|
const response = camelizeKeys(JSON.parse(data));
|
|
688
691
|
if ('error' in response) {
|
|
689
|
-
throw new
|
|
692
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
690
693
|
}
|
|
691
694
|
else {
|
|
692
695
|
// convert to array
|
|
@@ -741,7 +744,7 @@ function multipartComplete(uuid, { publicKey, baseURL = defaultSettings.baseURL,
|
|
|
741
744
|
}).then(({ data, headers, request }) => {
|
|
742
745
|
const response = camelizeKeys(JSON.parse(data));
|
|
743
746
|
if ('error' in response) {
|
|
744
|
-
throw new
|
|
747
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
745
748
|
}
|
|
746
749
|
else {
|
|
747
750
|
return response;
|
|
@@ -1066,13 +1069,13 @@ function pollStrategy({ token, publicKey, baseURL, integration, userAgent, retry
|
|
|
1066
1069
|
}).then((response) => {
|
|
1067
1070
|
switch (response.status) {
|
|
1068
1071
|
case Status.Error: {
|
|
1069
|
-
return new
|
|
1072
|
+
return new UploadError(response.error, response.errorCode);
|
|
1070
1073
|
}
|
|
1071
1074
|
case Status.Waiting: {
|
|
1072
1075
|
return false;
|
|
1073
1076
|
}
|
|
1074
1077
|
case Status.Unknown: {
|
|
1075
|
-
return new
|
|
1078
|
+
return new UploadError(`Token "${token}" was not found.`);
|
|
1076
1079
|
}
|
|
1077
1080
|
case Status.Progress: {
|
|
1078
1081
|
if (onProgress) {
|
|
@@ -1143,7 +1146,7 @@ const pushStrategy = ({ token, pusherKey, signal, onProgress }) => new Promise((
|
|
|
1143
1146
|
}
|
|
1144
1147
|
case Status.Error: {
|
|
1145
1148
|
destroy();
|
|
1146
|
-
reject(new
|
|
1149
|
+
reject(new UploadError(result.msg, result.error_code));
|
|
1147
1150
|
}
|
|
1148
1151
|
}
|
|
1149
1152
|
});
|
|
@@ -1196,7 +1199,7 @@ const uploadFromUrl = (sourceUrl, { publicKey, fileName, baseURL, baseCDN, check
|
|
|
1196
1199
|
}
|
|
1197
1200
|
})
|
|
1198
1201
|
.then((result) => {
|
|
1199
|
-
if (result instanceof
|
|
1202
|
+
if (result instanceof UploadError)
|
|
1200
1203
|
throw result;
|
|
1201
1204
|
return result;
|
|
1202
1205
|
})
|
|
@@ -1724,9 +1727,19 @@ class Queue {
|
|
|
1724
1727
|
}
|
|
1725
1728
|
}
|
|
1726
1729
|
|
|
1730
|
+
/* Low-Level API */
|
|
1731
|
+
/** @deprecated Please use NetworkError instead. */
|
|
1732
|
+
const UploadcareNetworkError = NetworkError;
|
|
1733
|
+
/** @deprecated Please use UploadError instead. */
|
|
1734
|
+
const UploadClientError = UploadError;
|
|
1735
|
+
|
|
1736
|
+
exports.CancelError = CancelError;
|
|
1737
|
+
exports.NetworkError = NetworkError;
|
|
1727
1738
|
exports.Queue = Queue;
|
|
1728
1739
|
exports.UploadClient = UploadClient;
|
|
1729
1740
|
exports.UploadClientError = UploadClientError;
|
|
1741
|
+
exports.UploadError = UploadError;
|
|
1742
|
+
exports.UploadcareError = UploadcareError;
|
|
1730
1743
|
exports.UploadcareFile = UploadcareFile;
|
|
1731
1744
|
exports.UploadcareGroup = UploadcareGroup;
|
|
1732
1745
|
exports.UploadcareNetworkError = UploadcareNetworkError;
|
|
@@ -19,7 +19,9 @@ export type GetUserAgentOptions = {
|
|
|
19
19
|
userAgent?: CustomUserAgent | null;
|
|
20
20
|
};
|
|
21
21
|
export declare function getUserAgent({ libraryName, libraryVersion, userAgent, publicKey, integration }: GetUserAgentOptions): string;
|
|
22
|
-
export declare class
|
|
22
|
+
export declare class UploadcareError extends Error {
|
|
23
|
+
}
|
|
24
|
+
export declare class NetworkError extends UploadcareError {
|
|
23
25
|
originalProgressEvent: ProgressEvent;
|
|
24
26
|
constructor(progressEvent: ProgressEvent);
|
|
25
27
|
}
|
|
@@ -72,6 +74,10 @@ export type ContentInfo = {
|
|
|
72
74
|
};
|
|
73
75
|
export type Metadata = Record<string, string>;
|
|
74
76
|
export type StoreValue = "auto" | boolean;
|
|
77
|
+
export declare class CancelError extends UploadcareError {
|
|
78
|
+
isCancel: boolean;
|
|
79
|
+
constructor(message?: string);
|
|
80
|
+
}
|
|
75
81
|
export interface DefaultSettings {
|
|
76
82
|
baseCDN: string;
|
|
77
83
|
baseURL: string;
|
|
@@ -207,6 +213,8 @@ export type FromUrlOptions = {
|
|
|
207
213
|
};
|
|
208
214
|
/** Uploading files from URL. */
|
|
209
215
|
export function fromUrl(sourceUrl: Url, { publicKey, baseURL, store, fileName, checkForUrlDuplicates, saveUrlForRecurrentUploads, secureSignature, secureExpire, source, signal, integration, userAgent, retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes, metadata }: FromUrlOptions): Promise<FromUrlSuccessResponse>;
|
|
216
|
+
/** @see https://uploadcare.com/api-refs/upload-api/#tag/Errors */
|
|
217
|
+
export type ServerErrorCode = "AccountBlockedError" | "AccountLimitsExceededError" | "AccountUnpaidError" | "AutostoreDisabledError" | "BaseViewsError" | "FileMetadataKeyDuplicatedError" | "FileMetadataKeyEmptyError" | "FileMetadataKeyForbiddenError" | "FileMetadataKeyLengthTooBigError" | "FileMetadataKeysNumberTooBigError" | "FileMetadataValueEmptyError" | "FileMetadataValueForbiddenError" | "FileMetadataValueLengthTooBigError" | "FileSizeLimitExceededError" | "MethodNotAllowedError" | "NullCharactersForbiddenError" | "PostRequestParserFailedError" | "ProjectPublicKeyInvalidError" | "ProjectPublicKeyRemovedError" | "ProjectPublicKeyRequiredError" | "RequestFileNumberLimitExceededError" | "RequestFiledsNumberLimitExceededError" | "RequestSizeLimitExceededError" | "RequestThrottledError" | "SignatureExpirationError" | "SignatureExpirationInvalidError" | "SignatureExpirationRequiredError" | "SignatureInvalidError" | "SignatureRequiredError" | "UploadAPIError" | "UploadFailedError" | "DownloadFileError" | "DownloadFileHTTPClientError" | "DownloadFileHTTPNetworkError" | "DownloadFileHTTPServerError" | "DownloadFileHTTPURLValidationError" | "DownloadFileInternalServerError" | "DownloadFileNotFoundError" | "DownloadFileSizeLimitExceededError" | "DownloadFileTaskFailedError" | "DownloadFileTimeLimitExceededError" | "DownloadFileValidationFailedError" | "FileIdInvalidError" | "FileIdNotUniqueError" | "FileIdRequiredError" | "FileNotFoundError" | "FileRequiredError" | "FilesNumberLimitExceededError" | "FilesRequiredError" | "InternalRequestForbiddenError" | "InternalRequestInvalidError" | "MultipartFileAlreadyUploadedError" | "MultipartFileCompletionFailedError" | "MultipartFileIdRequiredError" | "MultipartFileNotFoundError" | "MultipartFileSizeLimitExceededError" | "MultipartFileSizeTooSmallError" | "MultipartPartSizeInvalidError" | "MultipartPartSizeTooBigError" | "MultipartPartSizeTooSmallError" | "MultipartSizeInvalidError" | "MultipartUploadSizeTooLargeError" | "MultipartUploadSizeTooSmallError" | "RequestParamRequiredError" | "SourceURLRequiredError" | "TokenRequiredError" | "UUIDInvalidError" | "UploadViewsError" | "UploadcareFileIdDuplicatedError" | "UploadcareFileIdInvalidError" | "UploadcareFileIdRequiredError" | "GroupFileURLParsingFailedError" | "GroupFilesInvalidError" | "GroupFilesNotFoundError" | "GroupIdRequiredError" | "GroupNotFoundError" | "GroupViewsError" | "FileInfectedError" | "FileTypeForbiddenError" | "HostnameNotFoundError" | "URLBlacklistedError" | "URLHostMalformedError" | "URLHostPrivateIPForbiddenError" | "URLHostRequiredError" | "URLParsingFailedError" | "URLRedirectsLimitExceededError" | "URLSchemeInvalidError" | "URLSchemeRequiredError" | "URLValidationError";
|
|
210
218
|
export declare enum Status {
|
|
211
219
|
Unknown = "unknown",
|
|
212
220
|
Waiting = "waiting",
|
|
@@ -229,7 +237,7 @@ export type StatusProgressResponse = {
|
|
|
229
237
|
export type StatusErrorResponse = {
|
|
230
238
|
status: Status.Error;
|
|
231
239
|
error: string;
|
|
232
|
-
errorCode:
|
|
240
|
+
errorCode: ServerErrorCode;
|
|
233
241
|
};
|
|
234
242
|
export type StatusSuccessResponse = {
|
|
235
243
|
status: Status.Success;
|
|
@@ -520,16 +528,19 @@ export type ErrorResponseInfo = {
|
|
|
520
528
|
error?: {
|
|
521
529
|
statusCode: number;
|
|
522
530
|
content: string;
|
|
523
|
-
errorCode:
|
|
531
|
+
errorCode: ServerErrorCode;
|
|
524
532
|
};
|
|
525
533
|
};
|
|
526
|
-
export declare class
|
|
527
|
-
|
|
528
|
-
readonly code?: string;
|
|
534
|
+
export declare class UploadError extends UploadcareError {
|
|
535
|
+
readonly code?: ServerErrorCode;
|
|
529
536
|
readonly request?: ErrorRequestInfo;
|
|
530
537
|
readonly response?: ErrorResponseInfo;
|
|
531
538
|
readonly headers?: Headers;
|
|
532
|
-
constructor(message: string, code?:
|
|
539
|
+
constructor(message: string, code?: ServerErrorCode, request?: ErrorRequestInfo, response?: ErrorResponseInfo, headers?: Headers);
|
|
533
540
|
}
|
|
541
|
+
/** @deprecated Please use NetworkError instead. */
|
|
542
|
+
export declare const UploadcareNetworkError: typeof NetworkError;
|
|
543
|
+
/** @deprecated Please use UploadError instead. */
|
|
544
|
+
export declare const UploadClientError: typeof UploadError;
|
|
534
545
|
|
|
535
546
|
export {};
|
package/dist/cjs/index.node.cjs
CHANGED
|
@@ -98,13 +98,16 @@ function retrier(fn, options = defaultOptions) {
|
|
|
98
98
|
return runAttempt(fn);
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
class
|
|
101
|
+
class UploadcareError extends Error {
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
class NetworkError extends UploadcareError {
|
|
102
105
|
originalProgressEvent;
|
|
103
106
|
constructor(progressEvent) {
|
|
104
107
|
super();
|
|
105
|
-
this.name = '
|
|
108
|
+
this.name = 'NetworkError';
|
|
106
109
|
this.message = 'Network error';
|
|
107
|
-
Object.setPrototypeOf(this,
|
|
110
|
+
Object.setPrototypeOf(this, NetworkError.prototype);
|
|
108
111
|
this.originalProgressEvent = progressEvent;
|
|
109
112
|
}
|
|
110
113
|
}
|
|
@@ -120,10 +123,11 @@ const onCancel = (signal, callback) => {
|
|
|
120
123
|
}
|
|
121
124
|
};
|
|
122
125
|
|
|
123
|
-
class CancelError extends
|
|
126
|
+
class CancelError extends UploadcareError {
|
|
124
127
|
isCancel = true;
|
|
125
128
|
constructor(message = 'Request canceled') {
|
|
126
129
|
super(message);
|
|
130
|
+
this.name = 'CancelError';
|
|
127
131
|
Object.setPrototypeOf(this, CancelError.prototype);
|
|
128
132
|
}
|
|
129
133
|
}
|
|
@@ -379,21 +383,20 @@ function buildFormData(options) {
|
|
|
379
383
|
return formData;
|
|
380
384
|
}
|
|
381
385
|
|
|
382
|
-
class
|
|
383
|
-
isCancel;
|
|
386
|
+
class UploadError extends UploadcareError {
|
|
384
387
|
code;
|
|
385
388
|
request;
|
|
386
389
|
response;
|
|
387
390
|
headers;
|
|
388
391
|
constructor(message, code, request, response, headers) {
|
|
389
392
|
super();
|
|
390
|
-
this.name = '
|
|
393
|
+
this.name = 'UploadError';
|
|
391
394
|
this.message = message;
|
|
392
395
|
this.code = code;
|
|
393
396
|
this.request = request;
|
|
394
397
|
this.response = response;
|
|
395
398
|
this.headers = headers;
|
|
396
|
-
Object.setPrototypeOf(this,
|
|
399
|
+
Object.setPrototypeOf(this, UploadError.prototype);
|
|
397
400
|
}
|
|
398
401
|
}
|
|
399
402
|
|
|
@@ -428,7 +431,7 @@ const getUrl = (base, path, query) => {
|
|
|
428
431
|
return url.toString();
|
|
429
432
|
};
|
|
430
433
|
|
|
431
|
-
var version = '6.
|
|
434
|
+
var version = '6.12.0';
|
|
432
435
|
|
|
433
436
|
const LIBRARY_NAME = 'UploadcareUploadClient';
|
|
434
437
|
const LIBRARY_VERSION = version;
|
|
@@ -462,7 +465,7 @@ function retryIfFailed(fn, options) {
|
|
|
462
465
|
attempt < retryThrottledRequestMaxTimes) {
|
|
463
466
|
return retry(getTimeoutFromThrottledRequest(error));
|
|
464
467
|
}
|
|
465
|
-
if (error instanceof
|
|
468
|
+
if (error instanceof NetworkError &&
|
|
466
469
|
attempt < retryNetworkErrorMaxTimes) {
|
|
467
470
|
return retry((attempt + 1) * DEFAULT_NETWORK_ERROR_TIMEOUT);
|
|
468
471
|
}
|
|
@@ -530,7 +533,7 @@ function base(file, { publicKey, fileName, contentType, baseURL = defaultSetting
|
|
|
530
533
|
}).then(({ data, headers, request }) => {
|
|
531
534
|
const response = camelizeKeys(JSON.parse(data));
|
|
532
535
|
if ('error' in response) {
|
|
533
|
-
throw new
|
|
536
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
534
537
|
}
|
|
535
538
|
else {
|
|
536
539
|
return response;
|
|
@@ -567,7 +570,7 @@ function fromUrl(sourceUrl, { publicKey, baseURL = defaultSettings.baseURL, stor
|
|
|
567
570
|
}).then(({ data, headers, request }) => {
|
|
568
571
|
const response = camelizeKeys(JSON.parse(data));
|
|
569
572
|
if ('error' in response) {
|
|
570
|
-
throw new
|
|
573
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
571
574
|
}
|
|
572
575
|
else {
|
|
573
576
|
return response;
|
|
@@ -607,7 +610,7 @@ function fromUrlStatus(token, { publicKey, baseURL = defaultSettings.baseURL, si
|
|
|
607
610
|
}).then(({ data, headers, request }) => {
|
|
608
611
|
const response = camelizeKeys(JSON.parse(data));
|
|
609
612
|
if ('error' in response && !isErrorResponse(response)) {
|
|
610
|
-
throw new
|
|
613
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
611
614
|
}
|
|
612
615
|
else {
|
|
613
616
|
return response;
|
|
@@ -635,7 +638,7 @@ function group(uuids, { publicKey, baseURL = defaultSettings.baseURL, jsonpCallb
|
|
|
635
638
|
}).then(({ data, headers, request }) => {
|
|
636
639
|
const response = camelizeKeys(JSON.parse(data));
|
|
637
640
|
if ('error' in response) {
|
|
638
|
-
throw new
|
|
641
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
639
642
|
}
|
|
640
643
|
else {
|
|
641
644
|
return response;
|
|
@@ -660,7 +663,7 @@ function groupInfo(id, { publicKey, baseURL = defaultSettings.baseURL, signal, s
|
|
|
660
663
|
}).then(({ data, headers, request }) => {
|
|
661
664
|
const response = camelizeKeys(JSON.parse(data));
|
|
662
665
|
if ('error' in response) {
|
|
663
|
-
throw new
|
|
666
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
664
667
|
}
|
|
665
668
|
else {
|
|
666
669
|
return response;
|
|
@@ -685,7 +688,7 @@ function info(uuid, { publicKey, baseURL = defaultSettings.baseURL, signal, sour
|
|
|
685
688
|
}).then(({ data, headers, request }) => {
|
|
686
689
|
const response = camelizeKeys(JSON.parse(data));
|
|
687
690
|
if ('error' in response) {
|
|
688
|
-
throw new
|
|
691
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
689
692
|
}
|
|
690
693
|
else {
|
|
691
694
|
return response;
|
|
@@ -717,7 +720,7 @@ function multipartStart(size, { publicKey, contentType, fileName, multipartChunk
|
|
|
717
720
|
}).then(({ data, headers, request }) => {
|
|
718
721
|
const response = camelizeKeys(JSON.parse(data));
|
|
719
722
|
if ('error' in response) {
|
|
720
|
-
throw new
|
|
723
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
721
724
|
}
|
|
722
725
|
else {
|
|
723
726
|
// convert to array
|
|
@@ -772,7 +775,7 @@ function multipartComplete(uuid, { publicKey, baseURL = defaultSettings.baseURL,
|
|
|
772
775
|
}).then(({ data, headers, request }) => {
|
|
773
776
|
const response = camelizeKeys(JSON.parse(data));
|
|
774
777
|
if ('error' in response) {
|
|
775
|
-
throw new
|
|
778
|
+
throw new UploadError(response.error.content, response.error.errorCode, request, response, headers);
|
|
776
779
|
}
|
|
777
780
|
else {
|
|
778
781
|
return response;
|
|
@@ -1095,13 +1098,13 @@ function pollStrategy({ token, publicKey, baseURL, integration, userAgent, retry
|
|
|
1095
1098
|
}).then((response) => {
|
|
1096
1099
|
switch (response.status) {
|
|
1097
1100
|
case Status.Error: {
|
|
1098
|
-
return new
|
|
1101
|
+
return new UploadError(response.error, response.errorCode);
|
|
1099
1102
|
}
|
|
1100
1103
|
case Status.Waiting: {
|
|
1101
1104
|
return false;
|
|
1102
1105
|
}
|
|
1103
1106
|
case Status.Unknown: {
|
|
1104
|
-
return new
|
|
1107
|
+
return new UploadError(`Token "${token}" was not found.`);
|
|
1105
1108
|
}
|
|
1106
1109
|
case Status.Progress: {
|
|
1107
1110
|
if (onProgress) {
|
|
@@ -1172,7 +1175,7 @@ const pushStrategy = ({ token, pusherKey, signal, onProgress }) => new Promise((
|
|
|
1172
1175
|
}
|
|
1173
1176
|
case Status.Error: {
|
|
1174
1177
|
destroy();
|
|
1175
|
-
reject(new
|
|
1178
|
+
reject(new UploadError(result.msg, result.error_code));
|
|
1176
1179
|
}
|
|
1177
1180
|
}
|
|
1178
1181
|
});
|
|
@@ -1225,7 +1228,7 @@ const uploadFromUrl = (sourceUrl, { publicKey, fileName, baseURL, baseCDN, check
|
|
|
1225
1228
|
}
|
|
1226
1229
|
})
|
|
1227
1230
|
.then((result) => {
|
|
1228
|
-
if (result instanceof
|
|
1231
|
+
if (result instanceof UploadError)
|
|
1229
1232
|
throw result;
|
|
1230
1233
|
return result;
|
|
1231
1234
|
})
|
|
@@ -1756,9 +1759,19 @@ class Queue {
|
|
|
1756
1759
|
}
|
|
1757
1760
|
}
|
|
1758
1761
|
|
|
1762
|
+
/* Low-Level API */
|
|
1763
|
+
/** @deprecated Please use NetworkError instead. */
|
|
1764
|
+
const UploadcareNetworkError = NetworkError;
|
|
1765
|
+
/** @deprecated Please use UploadError instead. */
|
|
1766
|
+
const UploadClientError = UploadError;
|
|
1767
|
+
|
|
1768
|
+
exports.CancelError = CancelError;
|
|
1769
|
+
exports.NetworkError = NetworkError;
|
|
1759
1770
|
exports.Queue = Queue;
|
|
1760
1771
|
exports.UploadClient = UploadClient;
|
|
1761
1772
|
exports.UploadClientError = UploadClientError;
|
|
1773
|
+
exports.UploadError = UploadError;
|
|
1774
|
+
exports.UploadcareError = UploadcareError;
|
|
1762
1775
|
exports.UploadcareFile = UploadcareFile;
|
|
1763
1776
|
exports.UploadcareGroup = UploadcareGroup;
|
|
1764
1777
|
exports.UploadcareNetworkError = UploadcareNetworkError;
|
|
@@ -19,7 +19,9 @@ export type GetUserAgentOptions = {
|
|
|
19
19
|
userAgent?: CustomUserAgent | null;
|
|
20
20
|
};
|
|
21
21
|
export declare function getUserAgent({ libraryName, libraryVersion, userAgent, publicKey, integration }: GetUserAgentOptions): string;
|
|
22
|
-
export declare class
|
|
22
|
+
export declare class UploadcareError extends Error {
|
|
23
|
+
}
|
|
24
|
+
export declare class NetworkError extends UploadcareError {
|
|
23
25
|
originalProgressEvent: ProgressEvent;
|
|
24
26
|
constructor(progressEvent: ProgressEvent);
|
|
25
27
|
}
|
|
@@ -72,6 +74,10 @@ export type ContentInfo = {
|
|
|
72
74
|
};
|
|
73
75
|
export type Metadata = Record<string, string>;
|
|
74
76
|
export type StoreValue = "auto" | boolean;
|
|
77
|
+
export declare class CancelError extends UploadcareError {
|
|
78
|
+
isCancel: boolean;
|
|
79
|
+
constructor(message?: string);
|
|
80
|
+
}
|
|
75
81
|
export interface DefaultSettings {
|
|
76
82
|
baseCDN: string;
|
|
77
83
|
baseURL: string;
|
|
@@ -207,6 +213,8 @@ export type FromUrlOptions = {
|
|
|
207
213
|
};
|
|
208
214
|
/** Uploading files from URL. */
|
|
209
215
|
export function fromUrl(sourceUrl: Url, { publicKey, baseURL, store, fileName, checkForUrlDuplicates, saveUrlForRecurrentUploads, secureSignature, secureExpire, source, signal, integration, userAgent, retryThrottledRequestMaxTimes, retryNetworkErrorMaxTimes, metadata }: FromUrlOptions): Promise<FromUrlSuccessResponse>;
|
|
216
|
+
/** @see https://uploadcare.com/api-refs/upload-api/#tag/Errors */
|
|
217
|
+
export type ServerErrorCode = "AccountBlockedError" | "AccountLimitsExceededError" | "AccountUnpaidError" | "AutostoreDisabledError" | "BaseViewsError" | "FileMetadataKeyDuplicatedError" | "FileMetadataKeyEmptyError" | "FileMetadataKeyForbiddenError" | "FileMetadataKeyLengthTooBigError" | "FileMetadataKeysNumberTooBigError" | "FileMetadataValueEmptyError" | "FileMetadataValueForbiddenError" | "FileMetadataValueLengthTooBigError" | "FileSizeLimitExceededError" | "MethodNotAllowedError" | "NullCharactersForbiddenError" | "PostRequestParserFailedError" | "ProjectPublicKeyInvalidError" | "ProjectPublicKeyRemovedError" | "ProjectPublicKeyRequiredError" | "RequestFileNumberLimitExceededError" | "RequestFiledsNumberLimitExceededError" | "RequestSizeLimitExceededError" | "RequestThrottledError" | "SignatureExpirationError" | "SignatureExpirationInvalidError" | "SignatureExpirationRequiredError" | "SignatureInvalidError" | "SignatureRequiredError" | "UploadAPIError" | "UploadFailedError" | "DownloadFileError" | "DownloadFileHTTPClientError" | "DownloadFileHTTPNetworkError" | "DownloadFileHTTPServerError" | "DownloadFileHTTPURLValidationError" | "DownloadFileInternalServerError" | "DownloadFileNotFoundError" | "DownloadFileSizeLimitExceededError" | "DownloadFileTaskFailedError" | "DownloadFileTimeLimitExceededError" | "DownloadFileValidationFailedError" | "FileIdInvalidError" | "FileIdNotUniqueError" | "FileIdRequiredError" | "FileNotFoundError" | "FileRequiredError" | "FilesNumberLimitExceededError" | "FilesRequiredError" | "InternalRequestForbiddenError" | "InternalRequestInvalidError" | "MultipartFileAlreadyUploadedError" | "MultipartFileCompletionFailedError" | "MultipartFileIdRequiredError" | "MultipartFileNotFoundError" | "MultipartFileSizeLimitExceededError" | "MultipartFileSizeTooSmallError" | "MultipartPartSizeInvalidError" | "MultipartPartSizeTooBigError" | "MultipartPartSizeTooSmallError" | "MultipartSizeInvalidError" | "MultipartUploadSizeTooLargeError" | "MultipartUploadSizeTooSmallError" | "RequestParamRequiredError" | "SourceURLRequiredError" | "TokenRequiredError" | "UUIDInvalidError" | "UploadViewsError" | "UploadcareFileIdDuplicatedError" | "UploadcareFileIdInvalidError" | "UploadcareFileIdRequiredError" | "GroupFileURLParsingFailedError" | "GroupFilesInvalidError" | "GroupFilesNotFoundError" | "GroupIdRequiredError" | "GroupNotFoundError" | "GroupViewsError" | "FileInfectedError" | "FileTypeForbiddenError" | "HostnameNotFoundError" | "URLBlacklistedError" | "URLHostMalformedError" | "URLHostPrivateIPForbiddenError" | "URLHostRequiredError" | "URLParsingFailedError" | "URLRedirectsLimitExceededError" | "URLSchemeInvalidError" | "URLSchemeRequiredError" | "URLValidationError";
|
|
210
218
|
export declare enum Status {
|
|
211
219
|
Unknown = "unknown",
|
|
212
220
|
Waiting = "waiting",
|
|
@@ -229,7 +237,7 @@ export type StatusProgressResponse = {
|
|
|
229
237
|
export type StatusErrorResponse = {
|
|
230
238
|
status: Status.Error;
|
|
231
239
|
error: string;
|
|
232
|
-
errorCode:
|
|
240
|
+
errorCode: ServerErrorCode;
|
|
233
241
|
};
|
|
234
242
|
export type StatusSuccessResponse = {
|
|
235
243
|
status: Status.Success;
|
|
@@ -520,16 +528,19 @@ export type ErrorResponseInfo = {
|
|
|
520
528
|
error?: {
|
|
521
529
|
statusCode: number;
|
|
522
530
|
content: string;
|
|
523
|
-
errorCode:
|
|
531
|
+
errorCode: ServerErrorCode;
|
|
524
532
|
};
|
|
525
533
|
};
|
|
526
|
-
export declare class
|
|
527
|
-
|
|
528
|
-
readonly code?: string;
|
|
534
|
+
export declare class UploadError extends UploadcareError {
|
|
535
|
+
readonly code?: ServerErrorCode;
|
|
529
536
|
readonly request?: ErrorRequestInfo;
|
|
530
537
|
readonly response?: ErrorResponseInfo;
|
|
531
538
|
readonly headers?: Headers;
|
|
532
|
-
constructor(message: string, code?:
|
|
539
|
+
constructor(message: string, code?: ServerErrorCode, request?: ErrorRequestInfo, response?: ErrorResponseInfo, headers?: Headers);
|
|
533
540
|
}
|
|
541
|
+
/** @deprecated Please use NetworkError instead. */
|
|
542
|
+
export declare const UploadcareNetworkError: typeof NetworkError;
|
|
543
|
+
/** @deprecated Please use UploadError instead. */
|
|
544
|
+
export declare const UploadClientError: typeof UploadError;
|
|
534
545
|
|
|
535
546
|
export {};
|