Class: FaradayMiddleware::RaiseHttpException
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- FaradayMiddleware::RaiseHttpException
- Defined in:
- lib/phenoscaperb/faraday.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.
27 28 29 30 |
# File 'lib/phenoscaperb/faraday.rb', line 27 def initialize(app) super app @parser = nil end |
Instance Method Details
#call(env) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/phenoscaperb/faraday.rb', line 8 def call(env) @app.call(env).on_complete do |response| case response[:status].to_i when 400 raise Phenoscape::BadRequest, (response) when 404 raise Phenoscape::NotFound, (response) when 500 raise Phenoscape::InternalServerError, (response, "Something is technically wrong.") when 502 raise Phenoscape::BadGateway, (response, "The server returned an invalid or incomplete response.") when 503 raise Phenoscape::ServiceUnavailable, (response, "Crossref is rate limiting your requests.") when 504 raise Phenoscape::GatewayTimeout, (response, "504 Gateway Time-out") end end end |