-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Description
When the server responds with a status code referring to an error for example: 404, 405...
How should this be handled? Cause when using the Error boundary, I can't customize the fallback based on the error response from the server.
For example, in this code the server response with 404 error code.
const opened_cash = await OpeningBalance.findOne({
where: {
user_id,
branch_id,
is_previous_closed: false,
},
order: [['date', 'DESC']]
});
if(!opened_cash) {
return res.status(404).json({ message: 'Opened cash not found' });
}
In react i should be able to catch and handle this error based on the response code/message. Instead, I can't, I just show the global error or a default fallback from ErrorBoundary
component,
<ErrorBoundary
onError={(error) => {
console.log({ error: error.message });
}}
fallback={<div>Error loading dashboard</div>}
>
// main component
</ErrorBoundary>
Instead I want to do something in the main component, like based on the error show something.
Metadata
Metadata
Assignees
Labels
No labels