class Afterpay::ErrorMiddleware

Error middleware for Faraday to raise Afterpay connection errors

Public Class Methods

new(app) click to toggle source
# File lib/afterpay/client.rb, line 57
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# 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.dig(:body, "message")
    when 401
      raise Client::UnauthorizedError, env.dig(:body, "message")
    end
  end
end