1
0
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:
Yury Shkoda
2021-12-21 11:40:59 +03:00
parent 2ebd6e11ba
commit 4197ad5aa8
3 changed files with 21 additions and 7 deletions

View File

@@ -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
}
}
}