Merge pull request #14135 from alissonfabiano/af/fix-content-type-post-request

Fixed bug that when sending data by Post
This commit is contained in:
Johan Haals
2022-10-19 13:28:06 +02:00
committed by GitHub
2 changed files with 15 additions and 6 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-tech-insights': patch
---
Fixed bug when sending data by Post in `runChecks` and `runBulkChecks` functions of the `TechInsightsClient` class, the default `Content-Type` used was `plain/text`
@@ -105,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);