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
This commit is contained in:
sbYm 2018-07-03 22:17:15 +08:00 committed by Paulus Schoutsen
parent c0ae7d50ad
commit d299166f2a

View File

@ -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) {