-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
Strange behaviours when handling incorrect url #4244
Comments
Hi, this behaviour emegerges because deep down, axios uses the deprecated url.parse of the node url package: Line 120 in c5fe05b
This fails if no protocol is specified, and puts the remainings of the parsed string somewhere in the result object, but not in the correct fields. Thus, the field
There are two possible ways of dealing with this:
I'd like to take a shot at this together with @Arne117 (and add a unit test), but we are not yet sure which approach would work better. Any suggestions? |
Thank you very much for the detailed explanation. |
Keeping in mind that @jasonsaayman plans to refactor the whole project with #4209, maybe the small solution just throwing an error would be sufficient until the refactoring of this code. Switching I'm thinking of a regex check like |
Could we just specify the protocols axios supports? |
If you want to put in a pull request and tag me we can fix this before that release, there is quite a lot of people that have this problem or run into it. |
I've run into this today. Axios does not handle invalid URLs at all, resulting in such errors as: await axios.get('httdps://example.com')
// Error: Cannot read property 'replace' of null await axios.getUri('httdps://example.com')
// TypeError: Cannot use 'in' operator to search for 'validateStatus' in httdps://example.com And actually I'm surprised that the supposedly-equivalent |
Why close it without comment? |
This was said to be closed in another PR. Though I think doing something like axios.get('') in newer versions of axios still seems to result in funky behavior, for me at least. |
Is your feature request related to a problem? Please describe.
Today I was fixing a small bug caused by incorrect use of
url
. I specifiedurl
withouthttp://
orhttps://
. It took me hours to figure it out. There were two behaviours fromaxios
distracted me from identifying the real issue.axios
tries to reach127.0.0.1:80
. I had no clue why it happened, at first I didn't know it was caused byaxios
. So I created a mock server to run locally on port 80 and see where it was coming from, then this issue was gone and I was hit by another issue,axios
returns 400 error. This made me think the url I was calling returned 400.To Reproduce:
Describe the solution you'd like
axios
should throw proper error message (e.g.invalid url specified
).Describe alternatives you've considered
At the very least above behaviours should be avoided.
Additional context
The text was updated successfully, but these errors were encountered: