Class: Xero::Api::FaradayMiddleware::RaiseHttpException
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Xero::Api::FaradayMiddleware::RaiseHttpException
- Defined in:
- lib/xero/api/raise_http_exception.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ RaiseHttpException
constructor
A new instance of RaiseHttpException.
Constructor Details
#initialize(app) ⇒ RaiseHttpException
Returns a new instance of RaiseHttpException.
30 31 32 |
# File 'lib/xero/api/raise_http_exception.rb', line 30 def initialize(app) super app end |
Instance Method Details
#call(env) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/xero/api/raise_http_exception.rb', line 7 def call(env) @app.call(env).on_complete do |response| case response.status when 200 when 204 when 400 raise Xero::Api::BadRequest.new((response)) when 401 raise Xero::Api::Unauthorized.new((response)) when 404 raise Xero::Api::NotFound.new((response)) when 412 raise Xero::Api::PreconditionFailed.new((response)) when 500 raise Xero::Api::InternalError.new((response)) when 501 raise Xero::Api::NotImplemented.new((response)) when 503 raise Xero::Api::ServiceUnavailable.new((response)) end end end |