So, I read the article: "How to Handle API Errors"
In this article, it is proposed to divide errors into:
if (err.response) {
// client received an error response (5xx, 4xx)
} else if (err.request) {
// client never received a response, or request never left
} else {
// anything else
}
Ok, but how i can test this?
But what about request Errors? How can i simulate this error on frontend?
What you need is a testing framework, which could be something like Jest. Using a testing framework, you can mock the request to return an error you choose.
Heres a post with an answer which might be the same as your issue.