changed error handling to try providing most useful messages
This commit is contained in:
parent
db284fbf91
commit
704337e30b
|
@ -892,15 +892,14 @@
|
|||
xhr = new XMLHttpRequest();
|
||||
}
|
||||
xhr.onreadystatechange = function () {
|
||||
var data;
|
||||
if (xhr.readyState !== XMLHttpRequest.DONE) {
|
||||
// nothing to do here
|
||||
return;
|
||||
}
|
||||
|
||||
var data, err;
|
||||
if (xhr.status !== 200) {
|
||||
reject(new Error('bad status code: ' + xhr.status));
|
||||
return;
|
||||
err = new Error('bad status code: ' + xhr.status);
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -909,6 +908,15 @@
|
|||
data = xhr.responseText;
|
||||
}
|
||||
|
||||
if (data.error) {
|
||||
err = new Error(data.error.message || data.error_description || JSON.stringify(data.error));
|
||||
}
|
||||
if (err) {
|
||||
err.result = data;
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
|
||||
resolve({
|
||||
_request: xhr
|
||||
, headers: null // TODO
|
||||
|
|
|
@ -59,10 +59,7 @@ OAUTH3._node._parseJson = function (resp) {
|
|||
|
||||
// TODO toCamelCase
|
||||
if (!(resp.statusCode >= 200 && resp.statusCode < 400)) {
|
||||
// console.log('[A3] DEBUG', resp.body);
|
||||
err = new Error("bad response code: " + resp.statusCode);
|
||||
err.result = resp.body;
|
||||
return PromiseA.reject(err);
|
||||
}
|
||||
|
||||
//console.log('resp.body', typeof resp.body);
|
||||
|
@ -70,15 +67,16 @@ OAUTH3._node._parseJson = function (resp) {
|
|||
try {
|
||||
json = JSON.parse(json);
|
||||
} catch(e) {
|
||||
err = new Error('response not parsable:' + resp.body);
|
||||
err.result = resp.body;
|
||||
return PromiseA.reject(err);
|
||||
err = err || (new Error('response not parsable: ' + resp.body));
|
||||
}
|
||||
}
|
||||
|
||||
// handle both Oauth2- and node-style errors
|
||||
if (json.error) {
|
||||
err = new Error(json.error && json.error.message || json.error_description || json.error);
|
||||
if (json && json.error) {
|
||||
err = new Error(json.error.message || json.error_description || JSON.stringify(json.error));
|
||||
}
|
||||
|
||||
if (err) {
|
||||
err.result = json;
|
||||
return PromiseA.reject(err);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue