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.
37 38 39 40 |
# File 'lib/faraday/raise_http_exception.rb', line 37 def initialize(app) super app @parser = nil end |
Instance Method Details
#call(env) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/faraday/raise_http_exception.rb', line 6 def call(env) @app.call(env).on_complete do |response| case response[:status].to_i when 400 raise Taxjar::BadRequest, (response) when 401 raise Taxjar::NotAuthorized, (response) when 403 raise Taxjar::Forbidden, (response) when 404 raise Taxjar::NotFound, (response) when 405 raise Taxjar::MethodNotAllowed, (response) when 406 raise Taxjar::NotAcceptable, (response) when 410 raise Taxjar::Gone, (response) when 422 raise Taxjar::UnprocessableEntity, (response) when 429 raise Taxjar::TooManyRequests, (response) when 500 raise Taxjar::InternalServerError, (response, "Something is technically wrong.") when 503 raise Taxjar::ServiceUnavailable, (response, "Service is temporarily down for maintenance.") when 504 raise Taxjar::GatewayTimeout, (response, "504 Gateway Time-out") end end end |