Skip to content

Commit

Permalink
Fix error message display
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidMStraub committed Aug 24, 2024
1 parent ba16f34 commit 09d3083
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ export async function apiGet(endpoint, isJson = true) {
method: 'GET',
headers,
})
let resJson
try {
resJson = await resp.json()
} catch (error) {
resJson = {}
}
if (resp.status === 401) {
const refreshToken = localStorage.getItem('refresh_token')
if (refreshToken === null) {
Expand All @@ -274,11 +280,13 @@ export async function apiGet(endpoint, isJson = true) {
throw new Error('Authorization error')
}
if (resp.status !== 200) {
throw new Error(resp.statusText || `Error ${resp.status}`)
throw new Error(
resJson?.error?.message || resp.statusText || `Error ${resp.status}`
)
}
if (isJson) {
return {
data: await resp.json(),
data: resJson,
total_count: resp.headers.get('X-Total-Count'),
etag: resp.headers.get('ETag'),
}
Expand Down

0 comments on commit 09d3083

Please sign in to comment.