I have a web component (lwc) with a child component that makes an imperative server call. When an exception is thrown by the server the parent component is not catching it in the errorCallback. The parent errorCallback is working when the child throws from other parts of the code.
I'm ok to work around this and trigger an event to notify the parent but I wonder if this is expected behaviour?
pseudocode
/* parent.html */
<template>
<c-child></c-child>
</template>
/* parent.js */
import { LightningElement} from 'lwc';
export default class child extends LightningElement {
errorCallback(err){
console.log('parent error handler', err);
}
}
/* child.html */
<template>
</template>
/* child.js */
import { LightningElement } from 'lwc';
import getDataFromServer from '@salesforce/apex/apexController.getData';
export default class child extends LightningElement {
serverCall(){
getDataFromServer()
.then((data) => {
// process success
})
.catch((error) => {
console.error(error);
throw error?.body?.message;
});
}
}
}
I expected the console output to be 'parent error handler' but what I get is 'uncaught in promise'.