From 745ee8cced4b9834c7ee9d5bd84516430c4c8a65 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Fri, 5 Feb 2021 14:23:18 -0800 Subject: [PATCH] Return the error message instead of the http status code --- web/utils/apis.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/web/utils/apis.ts b/web/utils/apis.ts index 26063bf94..1972f5745 100644 --- a/web/utils/apis.ts +++ b/web/utils/apis.ts @@ -99,11 +99,12 @@ export async function fetchData(url: string, options?: FetchOptions) { try { const response = await fetch(url, requestOptions); + const json = await response.json(); + if (!response.ok) { - const message = `An error has occured: ${response.status}`; + const message = json.message || `An error has occurred: ${response.status}`; throw new Error(message); } - const json = await response.json(); return json; } catch (error) { return error;