Class: Chip::ErrorMiddleware
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Chip::ErrorMiddleware
- Defined in:
- lib/chip/error_middleware.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
7 8 9 |
# File 'lib/chip/error_middleware.rb', line 7 def body @body end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
7 8 9 |
# File 'lib/chip/error_middleware.rb', line 7 def status @status end |
Instance Method Details
#on_complete(env) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/chip/error_middleware.rb', line 9 def on_complete(env) return if env.success? @status = env[:status].to_i @body = env.body case status when 400..600 raise Chip::ServiceException.new("CHIP_#{status}", response_values(body), status, body) end end |
#response_values(body = {}) ⇒ Object (private)
22 23 24 25 26 27 28 |
# File 'lib/chip/error_middleware.rb', line 22 def response_values(body = {}) { status:, detail: [JSON.parse(body)], code: "CHIP_#{status}" } end |