- Mastering Reactive JavaScript
- Erich de Souza Oliveira
- 126字
- 2021-07-09 20:33:09
Acting when an error occurs
In the previous sections, we saw how to encapsulate an error on bacon.js. Now, we will use the OnError() method to take an action whenever this happens. This method has the same signature as that of the onValue() method and works similarly, but only for bacon errors. Now with this method, we can change the code we used in the previous section to print an error when it occurs. This is shown as follows:
var myCustomEventStream = Bacon.fromBinder(function(push){
push('some value');
push('other value');
push(new Bacon.Error('NOW AN ERROR HAPPENED'));
push('Now the stream will finish');
push(new Bacon.End());
});
myCustomEventStream
.onError((value)=>
console.log(value)
);
It will print the following:
NOW AN ERROR HAPPENED
As you might expect, the OnError() method also returns a function to unsubscribe.
推薦閱讀
- Mobile-first Bootstrap
- Kali Linux滲透測試全流程詳解
- Extending Puppet
- Implementing Azure DevOps Solutions
- Windows Phone 8 Application Development Essentials
- Linux服務器配置與管理
- 計算機系統的自主設計
- 跟老男孩學Linux運維:Shell編程實戰
- Kali Linux高級滲透測試(原書第3版)
- Web Penetration Testing with Kali Linux(Third Edition)
- 應急指揮信息系統設計
- 電腦辦公(Windows 7+Office 2016)入門與提高
- openEuler操作系統核心技術與行業應用實踐
- Getting Started with Raspberry Pi Zero
- Linux應用大全 服務器架設