From 098eeea204c1bdcf0a84ea083d58b31d803246dd Mon Sep 17 00:00:00 2001 From: Florian Maunier Date: Mon, 6 Nov 2023 10:28:05 +0100 Subject: [PATCH] Fix empty raw responses parsed as json --- src/protocols/Http.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/protocols/Http.ts b/src/protocols/Http.ts index bcc86fed6..ab7d2c98e 100644 --- a/src/protocols/Http.ts +++ b/src/protocols/Http.ts @@ -1,9 +1,9 @@ "use strict"; -import staticHttpRoutes from "./routes.json"; -import { KuzzleAbstractProtocol } from "./abstract/Base"; import { HttpRoutes, JSONObject } from "../types"; import { RequestPayload } from "../types/RequestPayload"; +import { KuzzleAbstractProtocol } from "./abstract/Base"; +import staticHttpRoutes from "./routes.json"; /** * Http protocol used to connect to a Kuzzle server. @@ -405,6 +405,10 @@ export default class HttpProtocol extends KuzzleAbstractProtocol { ); } + if (response.body === "") { + return ""; + } + return JSON.parse(response.body); }); } @@ -435,6 +439,10 @@ export default class HttpProtocol extends KuzzleAbstractProtocol { xhr.onload = () => { try { + if (xhr.responseText === "") { + resolve(""); + } + const json = JSON.parse(xhr.responseText); resolve(json); } catch (err) {