I am trying to implement a global uncaught promise error handler for a lightning web component. The goal is to reduce the catch(error) statements for promises:
getDocumentTypes() {
getDocumentTypes({ load: this.load })
.then(result => {
LightningUtil.processMessagesAndErrors2(this, result);
if(result.IsOK) {
this.documentTypes = result.Payload;
}
})
.catch(error => {
LightningUtil.logError(this, error);
});
}
I tried to implement an unhandledrejection event listener in an LWC:
constructor() {
super();
window.addEventListener('unhandledrejection', this.myFunction);
}
But the following error occurs in the console: Uncaught (in promise) Error: Lightning Web Security: Cannot add 'unhandledrejection' event listener to Window object.
Is this a limitation of the LWC SecureWindow and is there any other way to implement a global uncaught promise error handler?