Skip to content

Commit

Permalink
fix(auth): 🩹 throw SkolengoError if the API send an error message
Browse files Browse the repository at this point in the history
  • Loading branch information
maelgangloff committed May 6, 2023
1 parent 7943d50 commit fa8dfe2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scolengo-api",
"version": "1.1.3",
"version": "1.1.4",
"types": "types/index.d.ts",
"homepage": "https://github.com/maelgangloff/scolengo-api#readme",
"bugs": {
Expand Down
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -933,15 +933,18 @@ export class Skolengo {
const error = e as AxiosError<any>
const response = error.response

if (response === undefined || response.status !== 401) throw error
if (response === undefined) throw error

if (response.data.errors instanceof Array && response.data.errors.length > 0) {
throw new SkolengoError(response.data.errors[0])
}

if (response.status !== 401) throw error

const newTokenSet = await this.oidClient.refresh(this.tokenSet)

this.onTokenRefresh(newTokenSet)
this.tokenSet = newTokenSet

return await this.httpClient.request<T, R, D>({
...axiosConfig,
headers: {
Expand Down

0 comments on commit fa8dfe2

Please sign in to comment.