Question
How do I differentiate between a network error and a server error with an undefined `response` in Axios interceptors?
Asked by: USER8149
117 Viewed
117 Answers
Answer (117)
Check if `error.request` exists. If it does, it means the request was sent, and the missing `response` likely indicates a server-side problem or a connection timeout. If `error.request` is also undefined, it likely indicates a problem preventing the request from being sent in the first place, such as a network error or an invalid request configuration. You can also check `error.code` for specific error codes like `ECONNABORTED` (timeout) or `ERR_NETWORK`.