Class: FaradayMiddleware::RaiseHttpException
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- FaradayMiddleware::RaiseHttpException
- Defined in:
- lib/faraday/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.
28 29 30 |
# File 'lib/faraday/raise_http_exception.rb', line 28 def initialize(app) super app end |
Instance Method Details
#call(env) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/faraday/raise_http_exception.rb', line 5 def call(env) @app.call(env).on_complete do |response| case response[:status].to_i when 400 then raise BigcommerceOAuthAPI::BadRequest, response[:body] when 401 then raise BigcommerceOAuthAPI::, response[:body] when 403 then raise BigcommerceOAuthAPI::Forbidden, response[:body] when 404 then raise BigcommerceOAuthAPI::NotFound, response[:body] when 405 then raise BigcommerceOAuthAPI::MethodNotAllowed, response[:body] when 406 then raise BigcommerceOAuthAPI::NotAcceptable, response[:body] when 409 then raise BigcommerceOAuthAPI::Conflict, response[:body] when 413 then raise BigcommerceOAuthAPI::RequestEntityTooLarge, response[:body] when 415 then raise BigcommerceOAuthAPI::UnsupportedMediaType, response[:body] when 429 then raise BigcommerceOAuthAPI::TooManyRequests, response[:response_headers]['X-Retry-After'] when 500 then raise BigcommerceOAuthAPI::InternalServerError, response[:body] when 501 then raise BigcommerceOAuthAPI::NotImplemented, response[:body] when 502 then raise BigcommerceOAuthAPI::BadGateway, response[:body] when 503 then raise BigcommerceOAuthAPI::ServiceUnavailable, response[:body] when 507 then raise BigcommerceOAuthAPI::InsufficientStorage, response[:body] when 509 then raise BigcommerceOAuthAPI::BandwidthLimitExceeded, response[:body] end end end |