How can you distinguish between a network error and an HTTP error in Axios?

Responsive Ad Header

Question

Grade: Education Subject: Support
How can you distinguish between a network error and an HTTP error in Axios?
Asked by:
75 Viewed 75 Answers

Answer (75)

Best Answer
(407)
Network errors typically occur when there's a problem with the network connection or the server is unreachable (e.g., connection refused, timeout). HTTP errors, on the other hand, are returned by the server itself, indicating a problem with the request or the server's response (e.g., 404 Not Found, 500 Internal Server Error). The `response.status` property is key to differentiating these types of errors.