From 29a7b0451e9b6f4167ae36298841677dd87a6a5f Mon Sep 17 00:00:00 2001 From: Bruno Windels <274386+bwindels@users.noreply.github.com> Date: Fri, 13 Jan 2023 14:20:33 +0100 Subject: [PATCH] prevent errors in promises from being uncaught by returning a promise that has the error swallowed --- src/domain/ErrorReportViewModel.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/domain/ErrorReportViewModel.ts b/src/domain/ErrorReportViewModel.ts index eb6ed0aa..68fe580c 100644 --- a/src/domain/ErrorReportViewModel.ts +++ b/src/domain/ErrorReportViewModel.ts @@ -49,9 +49,12 @@ export class ErrorReportViewModel extends ViewModel protected logAndCatch(labelOrValues: LabelOrValues, callback: LogCallback, errorValue: T = undefined as unknown as T): T { try { - const result = this.logger.run(labelOrValues, callback); + let result = this.logger.run(labelOrValues, callback); 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; } catch (err) {