fix: default headers only if no headers present

This commit is contained in:
Michal Szczepanski 2023-09-19 04:33:30 +02:00
parent 6563f52b2f
commit 19edab9436
2 changed files with 10 additions and 5 deletions

4
bin/release Executable file

@ -0,0 +1,4 @@
#!/bin/bash
rm -r dist
rm -r .parcel-cache
npm run release

@ -30,7 +30,7 @@ export class FetchService {
rejectFetch: (error: Error) => void
): void => {
fnConsoleLog('FetchService->_fetch', url);
const headers = this.applyDefaultHeaders(params.headers);
const headers = params.headers ? params.headers : this.applyDefaultHeaders(params.headers);
// timeout
const timeout = setTimeout(() => {
fnConsoleLog('FetchService->timeout', url);
@ -110,11 +110,12 @@ export class FetchService {
private static applyDefaultHeaders(headers?: { [key: string]: string }): { [key: string]: string } {
if (!headers) headers = {};
else if (!('Content-Type' in headers))
Object.assign(headers, {
return Object.assign(
{
'Content-Type': 'application/json'
});
return headers;
},
headers
);
}
private static getResponse = async (req: Response, type: FetchResponseType): Promise<any> => {