Class: Afterpay::ErrorMiddleware
- Inherits:
-
Object
- Object
- Afterpay::ErrorMiddleware
- Defined in:
- lib/afterpay/client.rb
Overview
Error middleware for Faraday to raise Afterpay connection errors
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.
57 58 59 |
# File 'lib/afterpay/client.rb', line 57 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/afterpay/client.rb', line 61 def call(env) @app.call(env).on_complete do case env[:status] when 404 raise Client::NotFoundError, env.body[:message] when 401 raise Client::UnauthorizedError, env.body[:message] end end end |