New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
e.sent.data.forEach is not a function when getting invalid JSON response #3675
Comments
@L3P3 Hmm, are you sure? Can you share the error stack? The Axios source code doesn't contain the |
Hello! 👋 This issue is being automatically marked as stale because it has not been updated in a while. Please confirm that the issue is still present and reproducible. If no updates or new comments are received the issue will be closed in a few days. Thanks. |
Fixed in #3688 |
Describe the bug
I am working with a (not really clean/modern) PHP backend I don't have any control over. When there is a server error, it sometimes responds with bare php error printouts or simple html code, not formatted in JSON. In these cases, we don't get something like a "invalid format" exception from axios we could handle, but instead a cryptic JS error saying
e.sent.data.forEach is not a function
.We had this issue from day one, about 2 years ago. Since it is such an apparently obvious bug, we thought that just waiting will fix it. Nope. Wonder why no one else had this issue. 🤔
To Reproduce
Normally, we get JSON responses like this:
Or this:
Now, consider this myapi responds with something like this:
It were quite ugly to handle these cases via a
SyntaxError
and parsing the html alone but it is even uglier to catch a random, undocumented JS error thrown inside axios.Expected behavior
I expect to get a
SyntaxError
or something even more dedicated in case a JSON response is not actually valid JSON.Environment
Additional context/Screenshots
I am afraid I cannot give you any more screenshots than the message already stated in a message box.
Also cannot give you a stack trace for now as I currently do not have time for setting up the app locally.
The text was updated successfully, but these errors were encountered: