Class: Subledger::Store::Api::Errors::ResponseError
- Inherits:
-
Faraday::Response::Middleware
- Object
- Faraday::Response::Middleware
- Subledger::Store::Api::Errors::ResponseError
- Defined in:
- lib/subledger/store/api/errors.rb
Constant Summary collapse
- EXCEPTIONS =
{ 400 => BadRequest, 401 => Unauthorized, 403 => Forbidden, 404 => NotFound, 406 => NotAcceptable, 409 => Store::UpdateConflictError, 422 => UnprocessableEntity, 500 => InternalServerError, 501 => NotImplemented, 502 => BadGateway, 503 => ServiceUnavailable }
Instance Method Summary collapse
- #call(env) ⇒ Object
- #exception_for(status) ⇒ Object
- #response_for(env) ⇒ Object
- #url_for(env) ⇒ Object
Instance Method Details
#call(env) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/subledger/store/api/errors.rb', line 67 def call env @app.call(env).on_complete do status = env[:status].to_i if ( 400..600 ).include? status raise exception_for( status ), response_for( env ) end end end |
#exception_for(status) ⇒ Object
77 78 79 |
# File 'lib/subledger/store/api/errors.rb', line 77 def exception_for status EXCEPTIONS[status] || HttpError end |
#response_for(env) ⇒ Object
81 82 83 84 85 86 |
# File 'lib/subledger/store/api/errors.rb', line 81 def response_for env { :status => env[:status], :url => url_for( env ), :headers => env[:response_headers], :body => env[:body] } end |
#url_for(env) ⇒ Object
88 89 90 |
# File 'lib/subledger/store/api/errors.rb', line 88 def url_for env env[:url].to_s end |