From 2d7ad8d5b117984d30f082eb27e6d10005add4a1 Mon Sep 17 00:00:00 2001 From: Vicg853 Date: Mon, 10 Jan 2022 20:41:25 -0300 Subject: [PATCH] Adding unauthorized error handling in runMethod --- src/rest/runMethod.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/rest/runMethod.ts b/src/rest/runMethod.ts index e20e9efbd..17b1ef88b 100644 --- a/src/rest/runMethod.ts +++ b/src/rest/runMethod.ts @@ -35,6 +35,12 @@ export async function runMethod( throw errorStack; }); + if (!result.ok) { + errorStack.message = result.statusText as Error['message']; + console.error(`Invalid authorization key.`); + throw errorStack; + } + return result.status !== 204 ? await result.json() : undefined; }