Class: Acumatica::ErrorHandler

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/acumatica/errors.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ErrorHandler

Returns a new instance of ErrorHandler.



7
8
9
10
# File 'lib/acumatica/errors.rb', line 7

def initialize(app)
  super app
  @parser = nil
end

Instance Method Details

#call(request_env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/acumatica/errors.rb', line 12

def call(request_env)
  @app.call(request_env).on_complete do |env|
    case env[:status]
    when 400
      raise Acumatica::BadRequest, env
    when 401
      raise Acumatica::Unauthorized, env
    when 500
      raise Acumatica::InternalServerError, env
    end
  end
end