[#121] added error handler and snackbar
This commit is contained in:
committed by
Benoit TELLIER
parent
f498309f44
commit
a00f179dbd
@@ -0,0 +1,25 @@
|
||||
export class EventErrorHandler {
|
||||
private errors = new Map<string, string>();
|
||||
private onErrorCallback?: (messages: string[]) => void;
|
||||
|
||||
setErrorCallback(callback: (messages: string[]) => void) {
|
||||
this.onErrorCallback = callback;
|
||||
}
|
||||
|
||||
reportError(eventId: string, message: string) {
|
||||
if (!this.errors.has(eventId)) {
|
||||
this.errors.set(eventId, message);
|
||||
console.warn(`[EventErrorHandler] ${eventId}: ${message}`);
|
||||
this.emit();
|
||||
}
|
||||
}
|
||||
|
||||
clearAll() {
|
||||
this.errors.clear();
|
||||
this.emit();
|
||||
}
|
||||
|
||||
private emit() {
|
||||
this.onErrorCallback?.(Array.from(this.errors.values()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user