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.
32 33 34 35 |
# File 'lib/faraday/raise_http_exception.rb', line 32 def initialize(app) super app @parser = nil 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 29 30 |
# File 'lib/faraday/raise_http_exception.rb', line 7 def call(env) @app.call(env).on_complete do |response| case response[:status].to_i when 400 raise JurnalApi::BadRequest, (response) when 404 raise JurnalApi::NotFound, (response) when 409 raise JurnalApi::Conflict.new (response), response[:body] when 422 raise JurnalApi::UnprocessableEntity.new (response), response[:body] when 429 raise JurnalApi::TooManyRequests, (response) when 500 raise JurnalApi::InternalServerError, (response, "Something is went wrong.") when 502 raise JurnalApi::BadGateway, (response, "Bad gateway.") when 503 raise JurnalApi::ServiceUnavailable, (response, "Jurnal is rate limiting your requests.") when 504 raise JurnalApi::GatewayTimeout, (response, "504 Gateway Time-out") end end end |