1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-10 05:40:06 +00:00

fix(*): handled 404s, set correct accept headers

This commit is contained in:
Krishna Acondy
2021-01-28 19:25:23 +00:00
parent 23d151c919
commit 3c894c4147
6 changed files with 29 additions and 29 deletions

View File

@@ -2,6 +2,7 @@ import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'
import { CsrfToken, JobExecutionError } from '..'
import { LoginRequiredError } from '../types'
import { AuthorizeError } from '../types/AuthorizeError'
import { NotFoundError } from '../types/NotFoundError'
export interface HttpClient {
get<T>(
@@ -64,7 +65,6 @@ export class RequestClient implements HttpClient {
withCredentials: true
}
if (contentType === 'text/plain') {
requestConfig.headers.Accept = '*/*'
requestConfig.transformResponse = undefined
}
@@ -84,6 +84,8 @@ export class RequestClient implements HttpClient {
return this.get<T>(url, accessToken, contentType, overrideHeaders)
}
throw e
} else if (response?.status === 404) {
throw new NotFoundError(url)
}
throw e
}
@@ -272,6 +274,8 @@ export class RequestClient implements HttpClient {
if (contentType === 'text/plain') {
headers.Accept = '*/*'
} else {
headers.Accept = 'application/json'
}
if (accessToken) {
headers.Authorization = `Bearer ${accessToken}`