fixed reading headers

Signed-off-by: Alisson Fabiano <afabiano@eshopworld.com>
This commit is contained in:
Alisson Fabiano
2022-10-19 10:40:28 +01:00
parent e8cb790b1f
commit b8d4ab0e12
@@ -82,9 +82,6 @@ export class TechInsightsClient implements TechInsightsApi {
{
method: 'POST',
body: JSON.stringify(requestBody),
headers: {
'Content-Type': 'application/json',
},
},
);
}
@@ -101,9 +98,6 @@ export class TechInsightsClient implements TechInsightsApi {
return this.api('/checks/run', {
method: 'POST',
body: JSON.stringify(requestBody),
headers: {
'Content-Type': 'application/json',
},
});
}
@@ -111,14 +105,18 @@ export class TechInsightsClient implements TechInsightsApi {
const url = await this.discoveryApi.getBaseUrl('tech-insights');
const { token } = await this.identityApi.getCredentials();
const request = new Request(`${url}${path}`, init);
if (!request.headers.has('content-type')) {
request.headers.set('content-type', 'application/json');
}
if (token && !request.headers.has('authorization')) {
request.headers.set('authorization', `Bearer ${token}`);
const headers: HeadersInit = new Headers(init?.headers);
if (!headers.has('content-type'))
headers.set('content-type', 'application/json');
if (token && !headers.has('authorization')) {
headers.set('authorization', `Bearer ${token}`);
}
const request = new Request(`${url}${path}`, {
...init,
headers,
});
return fetch(request).then(async response => {
if (!response.ok) {
throw await ResponseError.fromResponse(response);