mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-16 00:20:06 +00:00
fix: raising error with details we get from server
This commit is contained in:
@@ -557,8 +557,18 @@ export class RequestClient implements HttpClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const throwIfError = (response: AxiosResponse) => {
|
export const throwIfError = (response: AxiosResponse) => {
|
||||||
if (response.status === 401) {
|
switch (response.status) {
|
||||||
throw new LoginRequiredError()
|
case 400:
|
||||||
|
if (typeof response.data === 'object') {
|
||||||
|
throw new LoginRequiredError(response.data)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case 401:
|
||||||
|
if (typeof response.data === 'object') {
|
||||||
|
throw new LoginRequiredError(response.data)
|
||||||
|
} else {
|
||||||
|
throw new LoginRequiredError()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.data?.entityID?.includes('login')) {
|
if (response.data?.entityID?.includes('login')) {
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
export class LoginRequiredError extends Error {
|
export class LoginRequiredError extends Error {
|
||||||
constructor() {
|
constructor(details?: any) {
|
||||||
super('Auth error: You must be logged in to access this resource')
|
const message = details
|
||||||
|
? JSON.stringify(details, null, 2)
|
||||||
|
: 'You must be logged in to access this resource'
|
||||||
|
|
||||||
|
super(`Auth error: ${message}`)
|
||||||
this.name = 'LoginRequiredError'
|
this.name = 'LoginRequiredError'
|
||||||
Object.setPrototypeOf(this, LoginRequiredError.prototype)
|
Object.setPrototypeOf(this, LoginRequiredError.prototype)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user