Extract error mesages better when throwing errors in core api client
This commit is contained in:
parent
86e0e8acc2
commit
978c3984e9
|
@ -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,
|
||||||
|
|
Loading…
Reference in New Issue