我使用rxjs5测试版来加载图片和做其他事情。但是,我不明白为什么.subscribe()不能处理404错误。是因为事件不会失败吗?下面是我的代码:
var image = new Image();
image.src = 'http://some.file/that/does/not-exist.jpg';
var sourceLoad = Rx.Observable.fromEvent(image, 'load');
var sourceError = Rx.Observable.fromEvent(image, 'error');
sourceLoad.subscribe(
function(e) {
console.log('loaded');
}/*,
function(e) {
console.log('Handling errors here is not working. Why?')
}
*/
);
sourceError.subscribe(
function(e) {
console.log('error');
}
);发布于 2016-01-14 11:18:10
试试这个:
var sourceLoad = Rx.Observable.from([1,2]).map(x => throw 'error here')
sourceLoad.subscribe(
x => console.log('A OK'),
err => console.log(err)
)ES5小提琴在这里:https://jsfiddle.net/jkennaly/7r3jgbhs/
https://stackoverflow.com/questions/34766615
复制相似问题