From bbc6d6fb76fcb274b337e6903f67ebc52bfb96dc Mon Sep 17 00:00:00 2001 From: Dmytro Krasun Date: Mon, 26 Aug 2024 17:21:11 +0300 Subject: [PATCH] Update example --- README.md | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 56990c6..8f2ff60 100644 --- a/README.md +++ b/README.md @@ -36,11 +36,24 @@ const url = client.generateTakeURL(options); console.log(url); // 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 -// or download the screenshot -const imageBlob = await client.take(options); -const buffer = Buffer.from(await imageBlob.arrayBuffer()); -fs.writeFileSync("example.png", buffer) -// the screenshot is store in the example.png file +// download the screenshot and handle potential API errors +try { + const imageBlob = await client.take(options); + + const buffer = Buffer.from(await imageBlob.arrayBuffer()); + fs.writeFileSync("example.png", buffer); +} catch (error) { + if (error instanceof screenshotone.APIError) { + // An API error occurred with + // HTTP Status Code: error.httpStatusCode + // Error Code: error.errorCode + // Error Message: error.errorMessage + // Documentation URL: error.documentationUrl + } else { + // An unexpected error occurred + console.error("An unexpected error occurred:", error.message); + } +} ``` ## Build and publish (a manual for SDK developers)