Skip to content
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

Handle proxy error #320

Open
MeterSoft opened this issue Mar 26, 2018 · 3 comments
Open

Handle proxy error #320

MeterSoft opened this issue Mar 26, 2018 · 3 comments

Comments

@MeterSoft
Copy link

How i can handle proxy error like
proxy error: "HTTP/1.1 503 Service Unavailable\r\nServer: squid/3.3.8\r\nMime-Version: 1.0\r\nDate: Mon, 05 Mar 2018 17:01:39 GMT\r\nContent-Type: text/html\r\nContent-Length: 3280\r\nX-Squid-Error: ERR_DNS_FAIL 0\r\nVary: Accept-Language\r\nContent-Langu

i have this code

case HTTPoison.get(url, headers, request_options) do
      {:ok, response} ->
        IO.inspect(response)
      {:error, %HTTPoison.Error{reason: reason}} ->
        IO.inspect(reason)
      {:error, error} ->
        IO.inspect(error)
      _ ->
        IO.inspect("Another error")
    end
@intangere
Copy link

Has anyone got a solution to this? I can't seem to catch this error.

@squarism
Copy link

@intangere Make sure you are not using async requests, use HTTPoison.get and not HTTPoison.get! (no exclamation mark) because that's going to not return right away. Then if you can not get pattern matching to work like the above, I don't know. {:error, error} will match a proxy error but if you want to be really specific with it you could do something like this:

# pretty much same code as above but with an additional specific pattern match:
      {:error, %HTTPoison.Error{reason: :proxy_error}} ->
        IO.puts("There was a proxy error")

You could do something else instead of IO.puts (I'm sure you already know this).

@MeterSoft
Copy link
Author

@squarism still not find solution. Can not catch proxy error anyway
also try this but it anyway put error into console
`
task = Task.async(fn ->
HTTPoison.get(url, @headers, request_options)
end)

        res = try do
          Task.await(task, Proxy.response_time)
        catch
          :proxy_error, _ ->
            {:error, :timeout}
          :exit, _ -> 
            Task.shutdown(task, :brutal_kill)
            {:error, :timeout}
        end

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants