Extract error mesages better when throwing errors in core api client

This commit is contained in:
Andrew Kingston 2022-01-20 13:37:06 +00:00
parent 9957acaccb
commit 4be465cf5a
1 changed files with 4 additions and 3 deletions

View File

@ -33,16 +33,17 @@ export const createAPIClient = config => {
*/ */
const makeErrorFromResponse = async response => { const makeErrorFromResponse = async response => {
// Try to read a message from the error // Try to read a message from the error
let message let message = response.statusText
try { try {
const json = await response.json() const json = await response.json()
if (json?.error) { if (json?.message) {
message = json.message
} else if (json?.error) {
message = json.error message = json.error
} }
} catch (error) { } catch (error) {
// Do nothing // Do nothing
} }
console.log("building error from", response)
return { return {
message, message,
status: response.status, status: response.status,