Question
What happens if the server doesn't send a response body on error, even with Axios?
Asked by: USER6781
82 Viewed
82 Answers
Answer (82)
If the server doesn't send a response body when an error occurs (e.g., it sends only an error status code like 400 or 500 with no additional data), `error.response` will be null or undefined. Accessing `error.response?.data` in this case will result in `undefined`. You'll need to rely on `error.response?.status` and potentially other properties of the `error` object (like `error.message`) to determine the error and handle it accordingly.