Class: Common::Client::Middleware::Response::RaiseError

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/common/client/middleware/response/raise_error.rb

Direct Known Subclasses

Rx::Middleware::Response::RxRaiseError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ RaiseError

Returns a new instance of RaiseError.



12
13
14
15
16
# File 'lib/common/client/middleware/response/raise_error.rb', line 12

def initialize(app, options = {})
  # set the error prefix to something like 'RX' or 'SM'
  @error_prefix = options[:error_prefix] || 'VA'
  super(app)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



10
11
12
# File 'lib/common/client/middleware/response/raise_error.rb', line 10

def body
  @body
end

#error_prefixObject (readonly)

Returns the value of attribute error_prefix.



10
11
12
# File 'lib/common/client/middleware/response/raise_error.rb', line 10

def error_prefix
  @error_prefix
end

#statusObject (readonly)

Returns the value of attribute status.



10
11
12
# File 'lib/common/client/middleware/response/raise_error.rb', line 10

def status
  @status
end

Instance Method Details

#on_complete(env) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/common/client/middleware/response/raise_error.rb', line 18

def on_complete(env)
  return if env.success?

  @body = env[:body]
  @status = env.status.to_i
  raise_error!
end