improve error when error response is not JSON

This commit is contained in:
Leo Horie 2014-06-04 08:30:12 -04:00
parent 161fbec443
commit 0f4f263441
2 changed files with 19 additions and 1 deletions

View file

@ -521,7 +521,8 @@ Mithril = m = new function app(window) {
deferred[e.type == "load" ? "resolve" : "reject"](response)
}
catch (e) {
if (e instanceof Error && e.constructor !== Error) throw e
if (e instanceof SyntaxError) throw new SyntaxError("Could not parse HTTP response. See http://lhorie.github.io/mithril/mithril.request.html#using-variable-data-formats")
else if (e instanceof Error && e.constructor !== Error) throw e
else deferred.reject(e)
}
if (xhrOptions.background !== true) m.endComputation()