screenshotone-api-sdk 1.1.14 → 1.1.15
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 +18 -5
- package/dist/@types/errors.d.ts +1 -2
- package/dist/@types/main.d.ts +2 -0
- package/dist/main.js +2 -1
- package/package.json +1 -1
- package/src/errors.ts +2 -4
- package/src/main.ts +2 -0
package/README.md
CHANGED
|
@@ -36,11 +36,24 @@ const url = client.generateTakeURL(options);
|
|
|
36
36
|
console.log(url);
|
|
37
37
|
// expected output: https://api.screenshotone.com/take?url=https%3A%2F%2Fexample.com&delay=3&block_ads=true&access_key=%3Caccess+key%3E&signature=7f3419ece2c53ed2c7923c7d5deef290d662c3643822bf69ec8259ce10b3ea61
|
|
38
38
|
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
// download the screenshot and handle potential API errors
|
|
40
|
+
try {
|
|
41
|
+
const imageBlob = await client.take(options);
|
|
42
|
+
|
|
43
|
+
const buffer = Buffer.from(await imageBlob.arrayBuffer());
|
|
44
|
+
fs.writeFileSync("example.png", buffer);
|
|
45
|
+
} catch (error) {
|
|
46
|
+
if (error instanceof screenshotone.APIError) {
|
|
47
|
+
// An API error occurred with
|
|
48
|
+
// HTTP Status Code: error.httpStatusCode
|
|
49
|
+
// Error Code: error.errorCode
|
|
50
|
+
// Error Message: error.errorMessage
|
|
51
|
+
// Documentation URL: error.documentationUrl
|
|
52
|
+
} else {
|
|
53
|
+
// An unexpected error occurred
|
|
54
|
+
console.error("An unexpected error occurred:", error.message);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
44
57
|
```
|
|
45
58
|
|
|
46
59
|
## Build and publish (a manual for SDK developers)
|
package/dist/@types/errors.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
export default class APIError extends Error {
|
|
2
2
|
readonly httpStatusCode?: number;
|
|
3
3
|
readonly errorCode?: string;
|
|
4
4
|
readonly errorMessage?: string;
|
|
5
5
|
readonly documentationUrl?: string;
|
|
6
6
|
constructor(message: string, httpStatusCode?: number, errorCode?: string, errorMessage?: string, documentationUrl?: string);
|
|
7
7
|
}
|
|
8
|
-
export default APIError;
|
package/dist/@types/main.d.ts
CHANGED
package/dist/main.js
CHANGED
|
@@ -3,11 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.AnimateOptions = exports.TakeOptions = exports.Client = void 0;
|
|
6
|
+
exports.AnimateOptions = exports.TakeOptions = exports.Client = exports.APIError = void 0;
|
|
7
7
|
const big_js_1 = __importDefault(require("big.js"));
|
|
8
8
|
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
|
9
9
|
const signature_1 = require("./signature");
|
|
10
10
|
const errors_1 = __importDefault(require("./errors"));
|
|
11
|
+
exports.APIError = errors_1.default;
|
|
11
12
|
const API_BASE_URL = "https://api.screenshotone.com";
|
|
12
13
|
const API_TAKE_PATH = "/take";
|
|
13
14
|
const API_ANIMATE_PATH = "/animate";
|
package/package.json
CHANGED
package/src/errors.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
class APIError extends Error {
|
|
2
|
+
export default class APIError extends Error {
|
|
3
3
|
public readonly httpStatusCode?: number;
|
|
4
4
|
public readonly errorCode?: string;
|
|
5
5
|
public readonly errorMessage?: string;
|
|
@@ -13,6 +13,4 @@ class APIError extends Error {
|
|
|
13
13
|
this.errorMessage = errorMessage;
|
|
14
14
|
this.documentationUrl = documentationUrl;
|
|
15
15
|
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export default APIError;
|
|
16
|
+
}
|