Skip to content

Commit 29ed459

Browse files
authored
feat: add uncaught rejections to support logs (#1293)
Closes #1253 - sample output logs: [console.txt](https://github.com/deephaven/web-client-ui/files/11466158/console.txt) - search for "can't handle this - ethan"
1 parent 02215b6 commit 29ed459

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

packages/log/src/LogProxy.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ export class LogProxy {
4949
);
5050
};
5151

52+
private handleUncaughtRejection = (event: PromiseRejectionEvent) => {
53+
const messages: string[] = [];
54+
if (event.promise != null) {
55+
messages.push(event.promise.toString());
56+
}
57+
if (event.reason as string) {
58+
messages.push(event.reason as string);
59+
}
60+
this.eventTarget.dispatchEvent(
61+
makeEvent(LOG_PROXY_TYPE.UNCAUGHT_ERROR, messages)
62+
);
63+
};
64+
5265
constructor() {
5366
this.debug = console.debug;
5467
this.log = console.log;
@@ -83,6 +96,7 @@ export class LogProxy {
8396
};
8497

8598
window.addEventListener('error', this.handleUncaughtError);
99+
window.addEventListener('unhandledrejection', this.handleUncaughtRejection);
86100

87101
// This forces logger to update its reference to the overriding functions instead of the original
88102
Log.setLogLevel(Log.level);
@@ -98,6 +112,10 @@ export class LogProxy {
98112
console.warn = this.warn;
99113
console.error = this.error;
100114
window.removeEventListener('error', this.handleUncaughtError);
115+
window.removeEventListener(
116+
'unhandledrejection',
117+
this.handleUncaughtRejection
118+
);
101119
Log.setLogLevel(Log.level);
102120
this.isEnabled = false;
103121
}

0 commit comments

Comments
 (0)