From 0e51dfed46a51cc38afc370531bd9ccf5597b1b7 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 23 Aug 2019 12:00:07 -0600 Subject: [PATCH] Don't convert errors to JSON if they are JSON already For example, if the identity server throws a 401 on `/account`, we end up here with a JSON object. Don't convert the string `object Object` to JSON because it'll fail: just use the object. --- src/http-api.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/http-api.js b/src/http-api.js index 48094ef66..2dfb228ba 100644 --- a/src/http-api.js +++ b/src/http-api.js @@ -836,7 +836,8 @@ function parseErrorResponse(response, body) { let err; if (contentType) { if (contentType.type === 'application/json') { - err = new module.exports.MatrixError(JSON.parse(body)); + const jsonBody = typeof(body) === 'object' ? body : JSON.parse(body); + err = new module.exports.MatrixError(jsonBody); } else if (contentType.type === 'text/plain') { err = new Error(`Server returned ${httpStatus} error: ${body}`); }