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 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
- // or download the screenshot
40
- const imageBlob = await client.take(options);
41
- const buffer = Buffer.from(await imageBlob.arrayBuffer());
42
- fs.writeFileSync("example.png", buffer)
43
- // the screenshot is store in the example.png file
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)
@@ -1,8 +1,7 @@
1
- declare class APIError extends Error {
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;
@@ -1,3 +1,5 @@
1
+ import APIError from "./errors";
2
+ export { APIError };
1
3
  /**
2
4
  * Represents an API client for the ScreenshotOne.com API.
3
5
  */
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "screenshotone-api-sdk",
3
3
  "homepage": "https://screenshotone.com",
4
- "version": "1.1.14",
4
+ "version": "1.1.15",
5
5
  "description": "Use ScreenshotOne.com API to generate screenshots of any website.",
6
6
  "repository": {
7
7
  "type": "git",
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
+ }
package/src/main.ts CHANGED
@@ -7,6 +7,8 @@ const API_BASE_URL = "https://api.screenshotone.com";
7
7
  const API_TAKE_PATH = "/take";
8
8
  const API_ANIMATE_PATH = "/animate";
9
9
 
10
+ export { APIError };
11
+
10
12
  /**
11
13
  * Represents an API client for the ScreenshotOne.com API.
12
14
  */