Skip to content

Commit 09d3083

Browse files
committed
Fix error message display
1 parent ba16f34 commit 09d3083

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/api.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,12 @@ export async function apiGet(endpoint, isJson = true) {
258258
method: 'GET',
259259
headers,
260260
})
261+
let resJson
262+
try {
263+
resJson = await resp.json()
264+
} catch (error) {
265+
resJson = {}
266+
}
261267
if (resp.status === 401) {
262268
const refreshToken = localStorage.getItem('refresh_token')
263269
if (refreshToken === null) {
@@ -274,11 +280,13 @@ export async function apiGet(endpoint, isJson = true) {
274280
throw new Error('Authorization error')
275281
}
276282
if (resp.status !== 200) {
277-
throw new Error(resp.statusText || `Error ${resp.status}`)
283+
throw new Error(
284+
resJson?.error?.message || resp.statusText || `Error ${resp.status}`
285+
)
278286
}
279287
if (isJson) {
280288
return {
281-
data: await resp.json(),
289+
data: resJson,
282290
total_count: resp.headers.get('X-Total-Count'),
283291
etag: resp.headers.get('ETag'),
284292
}

0 commit comments

Comments
 (0)