我有一个函数,在发生错误时(例如“超时”)应该抛出一个错误,我在承诺链的末尾捕获它。
var createOrder = function (id) {
Utility.toggleProgressBar();
return $.ajax({
url: 'http://' + AppVar.ServerUrlWithPort + '/restapi/CreateOrder',
data: JSON.stringify({
'SessionId': AppVar.SessionId,
'Idrmtreq': id
}),
}).then(function (response) {
if (response.ResultCode === '0') {
return response;
} else {
throw new Error($.i18n('Error-RetrivingDataProblem'));
}
}).fail(function (x, t, m) {
if (t === "timeout") {
throw new Error($.i18n('Error-Timeout')); //code reaches here, where Chrome debugger says that this error was left Uncaught
//for the record, I checked whether the translation function could be the problem and it doesn't work even when I do 'throw "timeout";'
} else {
throw new Error($.i18n('Error-ConnError'))
}
}).catch(function (error) {
//error == {"readyState":0,"status":0,"statusText":"timeout"}
ErrorManager.displayError(error);
return;
}).always(function () {
Utility.toggleProgressBar();
})
}
具体来说,我遇到了超时问题。代码到达投掷。我扔的球实际上没有被抓住,但有些东西被扔了。Catch 捕获包含此 Object 的错误{"readyState":0,"status":0,"statusText":"timeout"}
。
我不明白。扔什么?