Created
June 24, 2013 11:46
-
-
Save prcongithub/5849505 to your computer and use it in GitHub Desktop.
Faraday Exceptions
This file contains hidden or 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 422 | |
| raise Faraday::Error::UnprocessableEntity, response_values(env) | |
| 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