Skip to content

Commit df8c167

Browse files
committed
feat: add subscription on error handling
1 parent 560ae56 commit df8c167

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,9 @@ ee.once('some-event-name', (...args) => {
4040

4141
// Calls the appropriate event handlers, passing the agruments to the handlers.
4242
ee.emit('some-event-name', arg1, arg2, /*...*/, argN);
43+
44+
// subscribe to errors
45+
ee.on('error', (eventType, error) => {
46+
/* ... */
47+
})
4348
```

src/event-emitter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ class EventEmitter {
6565
this._events[type].forEach(fn => {
6666
try {
6767
fn(...args);
68-
} catch(e) {
69-
// TODO: add error handling
68+
} catch(error) {
69+
this.emit('error', type, error);
7070
}
7171
});
7272
};

0 commit comments

Comments
 (0)