ErrorsHandler.errorOccurred¶
ErrorsHandler.errorOccurred
is an event on the Event Bus that occurs whenever some global error occurs in the store.
Event body¶
Body of ErrorsHandler.errorOccurred
event has a TErrorHandlerErrorOccurredBody type which represents the details of the thrown error. It is optional so it might not exist.
Example¶
In this example we listen to ErrorsHandler.errorOccurred
event and perform an action whenever it's emitted.
useStorefront(async (storefront) => {
storefront.eventBus.on('ErrorsHandler.errorOccurred', ({ body: errorData }) => {
console.log('Some error occurred', errorData);
});
});
Example¶
In this example we use a Message Storage API to retrieve an array of past ErrorsHandler.errorOccurred
events.
useStorefront((storefront) => {
const messageStorageApi = storefront.getApiSync('messageStorageSystemApi');
const pastErrorOccurredEvents = messageStorageApi.getChannelMessages('ErrorsHandler.errorOccurred');
if (pastErrorOccurredEvents.length > 0) {
pastErrorOccurredEvents.forEach(({ body: eventBody }) => {
console.log('perform action on every past event');
});
}
});