Class: Epics::ParseEbics

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/epics/middleware/parse_ebics.rb

Instance Method Summary collapse

Constructor Details

#initialize(app = nil, options = {}) ⇒ ParseEbics


3
4
5
6
# File 'lib/epics/middleware/parse_ebics.rb', line 3

def initialize(app = nil, options = {})
  super(app)
  @client = options[:client]
end

Instance Method Details

#call(env) ⇒ Object


8
9
10
11
12
13
14
# File 'lib/epics/middleware/parse_ebics.rb', line 8

def call(env)
  @app.call(env).on_complete do |env|
    env[:body] = ::Epics::Response.new(@client, env[:body])
    raise Epics::Error::TechnicalError.new(env[:body].technical_code) if env[:body].technical_error?
    raise Epics::Error::BusinessError.new(env[:body].business_code)  if env[:body].business_error?
  end
end