Handling HTTP error responses
In this section, we'll configure the umi-request library to handle error responses and display visual feedback.
We'll use the errorHandler
function, one of the many umi-request library configurations. I recommend you read the documentation available at https://github.com/umijs/umi-request to learn more about other features.
The umi-request library will trigger the errorHandler
function every time it receives an HTTP error response, and we will read the response status and show a message to inform the user why the action they tried to execute failed.
Follow these steps to configure the umi-request library:
- In the
app.tsx
file, create a new function and add therequest
configuration as follows:const errorHandler = (error: ResponseError) => { const { response } = error; let messages = undefined; switch (getLocale()) { case 'en-US': ...