From b7c8a3f728bf87bcd12b92e68777cc803821096f Mon Sep 17 00:00:00 2001 From: ayan Date: Sat, 13 Apr 2024 21:11:58 +0530 Subject: [PATCH] fix: add fix for email request content-type issue --- src/transmission/transmission.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/transmission/transmission.ts b/src/transmission/transmission.ts index af9957e..d602aed 100644 --- a/src/transmission/transmission.ts +++ b/src/transmission/transmission.ts @@ -69,7 +69,7 @@ export function executeGetPayload( export function executePostPayload( url: string, - payload: T, + payload: T | FormData, headers: Headers | undefined, onPreExecute: () => void, onPostExecute: (response: ITransmissionResponse) => void, @@ -80,11 +80,22 @@ export function executePostPayload( onPreExecute(); - fetch(url, { + const requestOptions: RequestInit = { method: 'POST', - headers, - body: JSON.stringify(payload) - }) + headers: headers, + }; + + if (payload instanceof FormData) { + requestOptions.body = payload; + } else { + requestOptions.body = JSON.stringify(payload); + requestOptions.headers = { + ...requestOptions.headers, + 'Content-Type': 'application/json', + }; + } + + fetch(url, requestOptions) .then((response: Response) => response.json() as PromiseLike) .then( (response: ITransmissionResponse): void => {