Browse Source

Return the error message instead of the http status code

pull/1886/head
Gabe Kangas 6 years ago
parent
commit
745ee8cced
  1. 5
      web/utils/apis.ts

5
web/utils/apis.ts

@ -99,11 +99,12 @@ export async function fetchData(url: string, options?: FetchOptions) {
try { try {
const response = await fetch(url, requestOptions); const response = await fetch(url, requestOptions);
const json = await response.json();
if (!response.ok) { 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); throw new Error(message);
} }
const json = await response.json();
return json; return json;
} catch (error) { } catch (error) {
return error; return error;

Loading…
Cancel
Save