Created
October 29, 2014 17:32
-
-
Save adoseofjess/c7e928eb38c5f9972f96 to your computer and use it in GitHub Desktop.
Faraday Response::RaiseError
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Faraday | |
class Response::RaiseError < Response::Middleware | |
ClientErrorStatuses = 400...600 | |
def on_complete(env) | |
case env[:status] | |
when 404 | |
raise Faraday::Error::ResourceNotFound, response_values(env) | |
when 407 | |
# mimic the behavior that we get with proxy requests with HTTPS | |
raise Faraday::Error::ConnectionFailed, %{407 "Proxy Authentication Required "} | |
when ClientErrorStatuses | |
raise Faraday::Error::ClientError, response_values(env) | |
end | |
end | |
def response_values(env) | |
{:status => env.status, :headers => env.response_headers, :body => env.body} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment