Class: CFB::ErrorMiddleware
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- CFB::ErrorMiddleware
- Defined in:
- lib/cfb_api/middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ ErrorMiddleware
constructor
A new instance of ErrorMiddleware.
Constructor Details
#initialize(app) ⇒ ErrorMiddleware
Returns a new instance of ErrorMiddleware.
28 29 30 31 |
# File 'lib/cfb_api/middleware.rb', line 28 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 |
# File 'lib/cfb_api/middleware.rb', line 7 def call(env) @app.call(env).on_complete do |response| case response[:status].to_i when 400 raise CFB::BadRequest, (response) when 404 raise CFB::NotFound, (response) when 429 raise CFB::TooManyRequests, (response) when 500 raise CFB::InternalServerError, (response, 'Something is technically wrong.') when 502 raise CFB::BadGateway, (response, 'The server returned an invalid or incomplete response.') when 503 raise CFB::ServiceUnavailable, (response, 'Your requests are rate limited.') when 504 raise CFB::GatewayTimeout, (response, '504 Gateway Time-out') end end end |