Error catching for events
This commit is contained in:
parent
1d847b7d92
commit
ac912c0052
@ -1,3 +1,5 @@
|
|||||||
|
import { logger } from '../core';
|
||||||
|
|
||||||
export class ScopedEventEmitter {
|
export class ScopedEventEmitter {
|
||||||
private listeners: {[key: string]: any[]};
|
private listeners: {[key: string]: any[]};
|
||||||
public addEventListener = this.on;
|
public addEventListener = this.on;
|
||||||
@ -33,7 +35,12 @@ export class ScopedEventEmitter {
|
|||||||
const listener = this.listeners[name][i];
|
const listener = this.listeners[name][i];
|
||||||
|
|
||||||
if (listener.event === event && listener.func) {
|
if (listener.event === event && listener.func) {
|
||||||
|
try {
|
||||||
listener.func(...args);
|
listener.func(...args);
|
||||||
|
} catch (e) {
|
||||||
|
logger.error('An error occured in one of the listeners for "%s":',
|
||||||
|
event, e.stack);
|
||||||
|
}
|
||||||
|
|
||||||
if (listener.once) {
|
if (listener.once) {
|
||||||
this.listeners[name].splice(parseInt(i, 10), 1);
|
this.listeners[name].splice(parseInt(i, 10), 1);
|
||||||
@ -56,7 +63,12 @@ export class ScopedEventEmitter {
|
|||||||
const listener = this.listeners[name][i];
|
const listener = this.listeners[name][i];
|
||||||
|
|
||||||
if (listener.event === event && listener.func) {
|
if (listener.event === event && listener.func) {
|
||||||
|
try {
|
||||||
listener.func(...args);
|
listener.func(...args);
|
||||||
|
} catch (e) {
|
||||||
|
logger.error('An error occured in one of the listeners for "%s", stream "%s":',
|
||||||
|
event, name, e.stack);
|
||||||
|
}
|
||||||
|
|
||||||
if (listener.once) {
|
if (listener.once) {
|
||||||
this.listeners[name].splice(parseInt(i, 10), 1);
|
this.listeners[name].splice(parseInt(i, 10), 1);
|
||||||
|
Loading…
Reference in New Issue
Block a user