class Xero::Api::FaradayMiddleware::RaiseHttpException

@private

Public Class Methods

new(app) click to toggle source
Calls superclass method
# File lib/xero/api/raise_http_exception.rb, line 30
def initialize(app)
  super app
end

Public Instance Methods

call(env) click to toggle source
# File lib/xero/api/raise_http_exception.rb, line 7
def call(env)
  @app.call(env).on_complete do |response|
    case response.status
    when 200
    when 204
    when 400
      raise Xero::Api::BadRequest.new(error_message(response))
    when 401
      raise Xero::Api::Unauthorized.new(error_message(response))
    when 404
      raise Xero::Api::NotFound.new(error_message(response))
    when 412
      raise Xero::Api::PreconditionFailed.new(error_message(response))
    when 500
      raise Xero::Api::InternalError.new(error_message(response))
    when 501
      raise Xero::Api::NotImplemented.new(error_message(response))
    when 503
      raise Xero::Api::ServiceUnavailable.new(error_message(response))
    end
  end
end

Private Instance Methods

error_message(response) click to toggle source
# File lib/xero/api/raise_http_exception.rb, line 36
def error_message(response)
  error = ::JSON.parse(response.body)
rescue => e
  response.body
end