Skip to content

Commit

Permalink
Fix empty raw responses parsed as json
Browse files Browse the repository at this point in the history
  • Loading branch information
fmauNeko committed Nov 6, 2023
1 parent e4bdf50 commit 098eeea
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/protocols/Http.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -405,6 +405,10 @@ export default class HttpProtocol extends KuzzleAbstractProtocol {
);
}

if (response.body === "") {
return "";
}

return JSON.parse(response.body);
});
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 098eeea

Please sign in to comment.