Skip to content

Commit

Permalink
Parse Octyne HTTP errors in Ky
Browse files Browse the repository at this point in the history
  • Loading branch information
retrixe committed Jan 13, 2025
1 parent 7ab12c4 commit cf61522
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions imports/helpers/useKy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@ const defaultKy = ky.create({
beforeRequest: [
req => req.headers.set('Authorization', localStorage.getItem('ecthelion:token') ?? ''),
],
beforeError: [
async error => {
try {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
const data = await error.response?.json<{ error?: string }>()
if (data.error) {
error.name = 'OctyneError'
error.message = data.error
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (e: unknown) {
/* Do nothing */
}

return error
},
],
},
})

Expand Down

0 comments on commit cf61522

Please sign in to comment.