d8c931e02e
Co-authored-by: Camille Moussu <cmoussu@linagora.com>
28 lines
708 B
TypeScript
28 lines
708 B
TypeScript
export class EventErrorHandler {
|
|
private errors = new Map<string, string>();
|
|
private reportedEvents = new Set<string>();
|
|
private onErrorCallback?: (messages: string[]) => void;
|
|
|
|
setErrorCallback(callback: (messages: string[]) => void) {
|
|
this.onErrorCallback = callback;
|
|
}
|
|
|
|
reportError(eventId: string, message: string) {
|
|
if (!this.reportedEvents.has(eventId)) {
|
|
this.reportedEvents.add(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()));
|
|
}
|
|
}
|