Class: Virtuous::FaradayMiddleware::VirtuousErrorHandler
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Virtuous::FaradayMiddleware::VirtuousErrorHandler
- Defined in:
- lib/virtuous/error.rb
Constant Summary collapse
- ERROR_STATUSES =
(400..600).freeze
Instance Method Summary collapse
-
#on_complete(env) ⇒ Object
Throws an exception for responses with an HTTP error code.
Instance Method Details
#on_complete(env) ⇒ Object
Throws an exception for responses with an HTTP error code.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/virtuous/error.rb', line 21 def on_complete(env) = (env) case env[:status] when 400 raise Virtuous::BadRequest, when 401 raise Virtuous::Unauthorized, when 403 raise Virtuous::Forbidden, when 404 raise Virtuous::NotFound, when 500 raise Virtuous::InternalServerError, when 502 raise Virtuous::BadGateway, when 503 raise Virtuous::ServiceUnavailable, when 504 raise Virtuous::GatewayTimeout, when 520 raise Virtuous::CloudflareError, when ERROR_STATUSES raise Virtuous::Error, end end |