From b01b2eb07a2ceaa3ab5565e3d9bf7ade360337c9 Mon Sep 17 00:00:00 2001 From: Biswajeet Das Date: Wed, 25 Sep 2024 11:34:18 +0530 Subject: [PATCH] fix(client): handle empty or no content responses (#6561) --- .../client/src/http-client/http-client.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/client/src/http-client/http-client.ts b/packages/client/src/http-client/http-client.ts index d41343ceeac..ad44e712f85 100644 --- a/packages/client/src/http-client/http-client.ts +++ b/packages/client/src/http-client/http-client.ts @@ -58,6 +58,11 @@ export class HttpClient { method: 'POST', body: JSON.stringify(body), }); + const hasEmptyResponse = this.checkEmptyResponse(response); + if (hasEmptyResponse) { + return; + } + const data = await response.json(); return data.data; @@ -68,6 +73,11 @@ export class HttpClient { method: 'PATCH', body: JSON.stringify(body), }); + const hasEmptyResponse = this.checkEmptyResponse(response); + if (hasEmptyResponse) { + return; + } + const data = await response.json(); return data.data; @@ -78,6 +88,11 @@ export class HttpClient { method: 'DELETE', body: JSON.stringify(body), }); + const hasEmptyResponse = this.checkEmptyResponse(response); + if (hasEmptyResponse) { + return; + } + const data = await response.json(); return data.data; @@ -109,4 +124,12 @@ export class HttpClient { ); } } + + private checkEmptyResponse(response: Response) { + if (response.status === 204) { + return true; + } + + return false; + } }