From d299166f2a09acf586c646cbd31b429711438587 Mon Sep 17 00:00:00 2001 From: sbYm Date: Tue, 3 Jul 2018 22:17:15 +0800 Subject: [PATCH] Fix json detect (#1391) * Fix json detect Content-type is not always "application/json" when using nginx. eg: application/json; charset=utf-8 * Update hass-call-api.js * Lint * Lint 2 --- src/util/hass-call-api.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/util/hass-call-api.js b/src/util/hass-call-api.js index 230cd9ce1a..747843e665 100644 --- a/src/util/hass-call-api.js +++ b/src/util/hass-call-api.js @@ -12,9 +12,10 @@ export default function hassCallApi(host, auth, method, path, parameters) { } req.onload = function () { - var body = req.responseText; + let body = req.responseText; + const contentType = req.getResponseHeader('content-type'); - if (req.getResponseHeader('content-type') === 'application/json') { + if (contentType && contentType.indexOf('application/json') !== -1) { try { body = JSON.parse(req.responseText); } catch (err) {