-
Notifications
You must be signed in to change notification settings - Fork 120
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
Improve error messages on invalid URLs #186
Comments
Great catch! I agree we should clean these up and probably return |
I did some investigations and found that the reason of this iex(22)> Mint.HTTP.connect(:http, "", 80, [])
** (exit) :badarg
(kernel 8.3.1) gen_tcp.erl:218: :gen_tcp.connect/4
(mint 1.4.0) lib/mint/core/transport/tcp.ex:41: Mint.Core.Transport.TCP.connect/3
(mint 1.4.0) lib/mint/http1.ex:115: Mint.HTTP1.connect/4
iex(22)> Mint.HTTP.connect(:http, "über.de", 80, [])
** (exit) :badarg
(kernel 8.3.1) gen_tcp.erl:218: :gen_tcp.connect/4
(mint 1.4.0) lib/mint/core/transport/tcp.ex:41: Mint.Core.Transport.TCP.connect/3
(mint 1.4.0) lib/mint/http1.ex:115: Mint.HTTP1.connect/4 I'm interested to address this issue, but I'm also wondering how you'd like this Because What do you think? Or do you have any other ideas? |
I would insert a filter def get(url) do
with {:check_url, true} <- {:check_url, is_valid_url?(string)},
req <- Finch.build(:get,url),
{:ok, response} <- Finch.request(req, MyFinch) do
.....
else
{:check_url, false} ->
{:error, "invalid url"}
end
end
def is_valid_url?(string) do
map = URI.parse(string)
Enum.map([:scheme, :host, :port], &Map.get(map, &1))
|> Enum.all?()
end |
In wojtekmach/req#81, we noticed Finch exits on an invalid URL:
I did a quick survey of a couple of similar edge cases and here are the result:
(The
"https://"
one is especially odd!)All these errors are slightly different, perhaps it would be worthwhile to make them a bit more uniform.
The text was updated successfully, but these errors were encountered: