From aebd39d87483feec89112f8e3041ddcde7df4847 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 3 Nov 2021 13:12:20 +0000 Subject: [PATCH] Fixing REST PUT using POST as per #3227. --- packages/server/src/api/controllers/query.js | 3 --- packages/server/src/integrations/rest.ts | 14 ++++++-------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/packages/server/src/api/controllers/query.js b/packages/server/src/api/controllers/query.js index 89bf1a8ab0..a22cda4ebb 100644 --- a/packages/server/src/api/controllers/query.js +++ b/packages/server/src/api/controllers/query.js @@ -23,9 +23,6 @@ function formatResponse(resp) { try { resp = JSON.parse(resp) } catch (err) { - console.error( - "Error parsing JSON response. Returning string in array instead." - ) resp = { response: resp } } } diff --git a/packages/server/src/integrations/rest.ts b/packages/server/src/integrations/rest.ts index 9c6ece52d6..cf234518d9 100644 --- a/packages/server/src/integrations/rest.ts +++ b/packages/server/src/integrations/rest.ts @@ -142,13 +142,11 @@ module RestModule { } async parseResponse(response: any) { - switch (this.headers.Accept) { - case "application/json": - return await response.json() - case "text/html": - return await response.text() - default: - return await response.json() + const contentType = response.headers.get("content-type") + if (contentType && contentType.indexOf("application/json") !== -1) { + return await response.json() + } else { + return await response.text() } } @@ -191,7 +189,7 @@ module RestModule { } const response = await fetch(this.getUrl(path, queryString), { - method: "POST", + method: "PUT", headers: this.headers, body: JSON.stringify(json), })