prevent errors in promises from being uncaught

by returning a promise that has the error swallowed
This commit is contained in:
Bruno Windels 2023-01-13 14:20:33 +01:00
parent 80be2b7457
commit 29a7b0451e

View File

@ -49,9 +49,12 @@ export class ErrorReportViewModel<O extends Options = Options> extends ViewModel
protected logAndCatch<T>(labelOrValues: LabelOrValues, callback: LogCallback<T>, errorValue: T = undefined as unknown as T): T { protected logAndCatch<T>(labelOrValues: LabelOrValues, callback: LogCallback<T>, errorValue: T = undefined as unknown as T): T {
try { try {
const result = this.logger.run(labelOrValues, callback); let result = this.logger.run(labelOrValues, callback);
if (result instanceof Promise) { if (result instanceof Promise) {
result.catch(err => this.reportError(err)); result = result.catch(err => {
this.reportError(err);
return errorValue;
}) as unknown as T;
} }
return result; return result;
} catch (err) { } catch (err) {