我正在尝试使用Http服务发出Web请求。请求失败(正如预期的那样)并返回403.我希望onError处理程序可以执行,但事实并非如此。抛出异常并且从未被捕获。
_http(url: '/widgets/shiny-trinket', method: 'PUT', data: 'some malformed data')
.then((resp) => successHandler,
onError: (resp) {
// why aren't we getting here?
displayErrorMessage();
});
抛出的异常(来自控制台):
Failed to load resource: the server responded with a status of 403 (Forbidden)
http://localhost/widgets/shiny-trinket
Instance of '_XMLHttpRequestProgressEvent'
STACKTRACE:
null
我做错了吗?或者这是一个错误吗?
更新
我也尝试了以下内容,它也无效。
_http(url: '/widgets/shiny-trinket', method: 'PUT', data: 'some malformed data')
.then((resp) => successHandler)
.catchError((e) {
// why aren't we getting here?
displayErrorMessage();
});
答案 0 :(得分:0)
我刚尝试了问题How do I get Geolocation API to work in Dartium?中的示例,该示例产生了403错误,并且打印了catchError中的错误消息。
window.navigator
.geolocation.getCurrentPosition()
..then((pos) {
window.alert(pos.toString());
})
..catchError((PositionError error) {
window.alert("Error code: ${error.code}, Error message: ${error.message}");
})
..whenComplete(() => window.alert("complete"))
;
答案 1 :(得分:0)
这似乎是一个错误。我已经提交了拉取请求here。