From a7603c4838119e3519a9e4561907f809d3ce4328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rcio=20Barbosa?= <52362496+barbmarcio@users.noreply.github.com> Date: Thu, 15 Aug 2024 17:09:24 +0100 Subject: [PATCH] fix: add condition for no-content http code This PR adds validation to the response handler to ensure we do not attempt to parse responses with empty content. --- src/lib/api-client.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/api-client.ts b/src/lib/api-client.ts index 77d418f..62c3eb6 100644 --- a/src/lib/api-client.ts +++ b/src/lib/api-client.ts @@ -4,7 +4,11 @@ import AppError from "./app-error"; class APIClient { private async handleResponse(response: Response): Promise { - const data: unknown = await response.json(); + let data: unknown; + + if (response.status !== 204) { + data = await response.json(); + } if (!response.ok) { const retry = response.status === 429 || response.status >= 500;