screenshotone-api-sdk 1.2.0 → 1.3.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/README.md +1 -0
- package/dist/@types/errors.d.ts +6 -1
- package/dist/errors.js +2 -1
- package/dist/main.js +7 -3
- package/package.json +1 -1
- package/src/errors.ts +7 -1
- package/src/main.ts +11 -3
package/README.md
CHANGED
|
@@ -49,6 +49,7 @@ try {
|
|
|
49
49
|
// Error Code: error.errorCode
|
|
50
50
|
// Error Message: error.errorMessage
|
|
51
51
|
// Documentation URL: error.documentationUrl
|
|
52
|
+
// Site's HTTP status code for "host_returned_error": error.returnedStatusCode
|
|
52
53
|
} else if (error instanceof screenshotone.ConnectionError) {
|
|
53
54
|
// The connection to the API failed, for example with ECONNRESET.
|
|
54
55
|
// error.message explains what happened and what usually causes it.
|
package/dist/@types/errors.d.ts
CHANGED
|
@@ -3,7 +3,12 @@ export default class APIError extends Error {
|
|
|
3
3
|
readonly errorCode?: string;
|
|
4
4
|
readonly errorMessage?: string;
|
|
5
5
|
readonly documentationUrl?: string;
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* The HTTP status code the target site returned, for example 404 or 503.
|
|
8
|
+
* Set for the "host_returned_error" error code.
|
|
9
|
+
*/
|
|
10
|
+
readonly returnedStatusCode?: number;
|
|
11
|
+
constructor(message: string, httpStatusCode?: number, errorCode?: string, errorMessage?: string, documentationUrl?: string, returnedStatusCode?: number);
|
|
7
12
|
}
|
|
8
13
|
/**
|
|
9
14
|
* Where the connection failed: before the API responded ("request") or while
|
package/dist/errors.js
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ConnectionError = void 0;
|
|
4
4
|
class APIError extends Error {
|
|
5
|
-
constructor(message, httpStatusCode, errorCode, errorMessage, documentationUrl) {
|
|
5
|
+
constructor(message, httpStatusCode, errorCode, errorMessage, documentationUrl, returnedStatusCode) {
|
|
6
6
|
super(message);
|
|
7
7
|
this.httpStatusCode = httpStatusCode;
|
|
8
8
|
this.errorCode = errorCode;
|
|
9
9
|
this.errorMessage = errorMessage;
|
|
10
10
|
this.documentationUrl = documentationUrl;
|
|
11
|
+
this.returnedStatusCode = returnedStatusCode;
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
14
|
exports.default = APIError;
|
package/dist/main.js
CHANGED
|
@@ -81,6 +81,10 @@ function networkFailureCode(error) {
|
|
|
81
81
|
}
|
|
82
82
|
// the request URL without its query and fragment, which hold the access key
|
|
83
83
|
// and the signature, whatever the URL's form
|
|
84
|
+
function returnedStatusCode(data) {
|
|
85
|
+
const code = Number(data?.returned_status_code);
|
|
86
|
+
return Number.isInteger(code) && code > 0 ? code : undefined;
|
|
87
|
+
}
|
|
84
88
|
function withoutQuery(url) {
|
|
85
89
|
return url.split(/[?#]/, 1)[0];
|
|
86
90
|
}
|
|
@@ -281,7 +285,7 @@ class Client {
|
|
|
281
285
|
}
|
|
282
286
|
try {
|
|
283
287
|
const data = await this.read(request, (r) => r.json());
|
|
284
|
-
throw new errors_1.default(`Failed to generate screenshot, response returned ${response.status} (${response.statusText}): ${data?.error_message}`, response.status, data?.error_code, data?.error_message, data?.documentation_url);
|
|
288
|
+
throw new errors_1.default(`Failed to generate screenshot, response returned ${response.status} (${response.statusText}): ${data?.error_message}`, response.status, data?.error_code, data?.error_message, data?.documentation_url, returnedStatusCode(data));
|
|
285
289
|
}
|
|
286
290
|
catch (e) {
|
|
287
291
|
if (e instanceof errors_1.default || e instanceof errors_1.ConnectionError) {
|
|
@@ -307,7 +311,7 @@ class Client {
|
|
|
307
311
|
}
|
|
308
312
|
try {
|
|
309
313
|
const data = await this.read(request, (r) => r.json());
|
|
310
|
-
throw new errors_1.default(`Failed to generate animation, response returned ${response.status} (${response.statusText}): ${data?.error_message}`, response.status, data?.error_code, data?.error_message, data?.documentation_url);
|
|
314
|
+
throw new errors_1.default(`Failed to generate animation, response returned ${response.status} (${response.statusText}): ${data?.error_message}`, response.status, data?.error_code, data?.error_message, data?.documentation_url, returnedStatusCode(data));
|
|
311
315
|
}
|
|
312
316
|
catch (e) {
|
|
313
317
|
if (e instanceof errors_1.default || e instanceof errors_1.ConnectionError) {
|
|
@@ -353,7 +357,7 @@ class Client {
|
|
|
353
357
|
};
|
|
354
358
|
}
|
|
355
359
|
const data = await this.read(request, (r) => r.json());
|
|
356
|
-
throw new errors_1.default(`Failed to generate animation, response returned ${response.status} (${response.statusText}): ${data?.error_message}`, response.status, data?.error_code, data?.error_message, data?.documentation_url);
|
|
360
|
+
throw new errors_1.default(`Failed to generate animation, response returned ${response.status} (${response.statusText}): ${data?.error_message}`, response.status, data?.error_code, data?.error_message, data?.documentation_url, returnedStatusCode(data));
|
|
357
361
|
});
|
|
358
362
|
}
|
|
359
363
|
}
|
package/package.json
CHANGED
package/src/errors.ts
CHANGED
|
@@ -4,14 +4,20 @@ export default class APIError extends Error {
|
|
|
4
4
|
public readonly errorCode?: string;
|
|
5
5
|
public readonly errorMessage?: string;
|
|
6
6
|
public readonly documentationUrl?: string;
|
|
7
|
+
/**
|
|
8
|
+
* The HTTP status code the target site returned, for example 404 or 503.
|
|
9
|
+
* Set for the "host_returned_error" error code.
|
|
10
|
+
*/
|
|
11
|
+
public readonly returnedStatusCode?: number;
|
|
7
12
|
|
|
8
|
-
constructor(message: string, httpStatusCode?: number, errorCode?: string, errorMessage?: string, documentationUrl?: string) {
|
|
13
|
+
constructor(message: string, httpStatusCode?: number, errorCode?: string, errorMessage?: string, documentationUrl?: string, returnedStatusCode?: number) {
|
|
9
14
|
super(message);
|
|
10
15
|
|
|
11
16
|
this.httpStatusCode = httpStatusCode;
|
|
12
17
|
this.errorCode = errorCode;
|
|
13
18
|
this.errorMessage = errorMessage;
|
|
14
19
|
this.documentationUrl = documentationUrl;
|
|
20
|
+
this.returnedStatusCode = returnedStatusCode;
|
|
15
21
|
}
|
|
16
22
|
}
|
|
17
23
|
|
package/src/main.ts
CHANGED
|
@@ -97,6 +97,11 @@ function networkFailureCode(error: unknown): string | undefined {
|
|
|
97
97
|
|
|
98
98
|
// the request URL without its query and fragment, which hold the access key
|
|
99
99
|
// and the signature, whatever the URL's form
|
|
100
|
+
function returnedStatusCode(data: any): number | undefined {
|
|
101
|
+
const code = Number(data?.returned_status_code);
|
|
102
|
+
return Number.isInteger(code) && code > 0 ? code : undefined;
|
|
103
|
+
}
|
|
104
|
+
|
|
100
105
|
function withoutQuery(url: string): string {
|
|
101
106
|
return url.split(/[?#]/, 1)[0];
|
|
102
107
|
}
|
|
@@ -376,7 +381,8 @@ export class Client {
|
|
|
376
381
|
response.status,
|
|
377
382
|
data?.error_code,
|
|
378
383
|
data?.error_message,
|
|
379
|
-
data?.documentation_url
|
|
384
|
+
data?.documentation_url,
|
|
385
|
+
returnedStatusCode(data)
|
|
380
386
|
);
|
|
381
387
|
} catch (e) {
|
|
382
388
|
if (e instanceof APIError || e instanceof ConnectionError) {
|
|
@@ -413,7 +419,8 @@ export class Client {
|
|
|
413
419
|
response.status,
|
|
414
420
|
data?.error_code,
|
|
415
421
|
data?.error_message,
|
|
416
|
-
data?.documentation_url
|
|
422
|
+
data?.documentation_url,
|
|
423
|
+
returnedStatusCode(data)
|
|
417
424
|
);
|
|
418
425
|
} catch (e) {
|
|
419
426
|
if (e instanceof APIError || e instanceof ConnectionError) {
|
|
@@ -482,7 +489,8 @@ export class Client {
|
|
|
482
489
|
response.status,
|
|
483
490
|
data?.error_code,
|
|
484
491
|
data?.error_message,
|
|
485
|
-
data?.documentation_url
|
|
492
|
+
data?.documentation_url,
|
|
493
|
+
returnedStatusCode(data)
|
|
486
494
|
);
|
|
487
495
|
});
|
|
488
496
|
}
|