mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-10 22:00:05 +00:00
test(RequestClient): fix error handling
This commit is contained in:
@@ -215,6 +215,7 @@ export class RequestClient implements HttpClient {
|
||||
.post<T>(url, data, { headers, withCredentials: true })
|
||||
.then((response) => {
|
||||
throwIfError(response)
|
||||
|
||||
return this.parseResponse<T>(response)
|
||||
})
|
||||
.catch(async (e) => {
|
||||
@@ -464,6 +465,8 @@ export class RequestClient implements HttpClient {
|
||||
|
||||
if (e instanceof LoginRequiredError) {
|
||||
this.clearCsrfTokens()
|
||||
|
||||
throw e
|
||||
}
|
||||
|
||||
if (response?.status === 403 || response?.status === 449) {
|
||||
@@ -486,7 +489,8 @@ export class RequestClient implements HttpClient {
|
||||
else return
|
||||
}
|
||||
|
||||
throw prefixMessage(e, 'Error while handling error. ')
|
||||
if (e.message) throw e
|
||||
else throw prefixMessage(e, 'Error while handling error. ')
|
||||
}
|
||||
|
||||
protected parseResponse<T>(response: AxiosResponse<any>) {
|
||||
@@ -538,8 +542,9 @@ export class RequestClient implements HttpClient {
|
||||
|
||||
this.httpClient = createAxiosInstance(baseUrl, httpsAgent)
|
||||
|
||||
this.httpClient.defaults.validateStatus = (status) =>
|
||||
status >= 200 && status < 401
|
||||
this.httpClient.defaults.validateStatus = (status) => {
|
||||
return status >= 200 && status <= 401
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user