From c43c9ec211f30351e273a1c1be22950eecff5e6f Mon Sep 17 00:00:00 2001 From: Krishna Acondy Date: Thu, 10 Sep 2020 09:30:56 +0100 Subject: [PATCH] chore(edit-context): add error handling for fetch --- src/SASViyaApiClient.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/SASViyaApiClient.ts b/src/SASViyaApiClient.ts index 73c9c5c..6f597c5 100644 --- a/src/SASViyaApiClient.ts +++ b/src/SASViyaApiClient.ts @@ -302,7 +302,18 @@ export class SASViyaApiClient { { headers } - ) + ).catch((e) => { + console.error(e) + + if (e && e.status === 404) { + throw new Error( + `The context with ID ${contextId} was not found on this server.` + ) + } + throw new Error( + `An error occurred when fetching the context with ID ${contextId}` + ) + }) // An If-Match header with the value of the last ETag for the context // is required to be able to update it