Exception: ManagementAPIV2::Exception

Inherits:
StandardError
  • Object
show all
Defined in:
app/services/management_api_v2/exception.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response_or_ex = "External services error") ⇒ Exception

Returns a new instance of Exception.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/services/management_api_v2/exception.rb', line 7

def initialize(response_or_ex="External services error")
  @status = 503
  if response_or_ex.respond_to?(:body)
    @status = 422
    body = response_or_ex.body || {}

    if body.fetch("error", false)
      super body.fetch("error")
    elsif body.fetch("errors", false)
      super Array(body.fetch("errors")).first
    else
      super response_or_ex.body
    end
  else
    super response_or_ex
  end
end

Instance Attribute Details

#statusObject

Returns the value of attribute status.



5
6
7
# File 'app/services/management_api_v2/exception.rb', line 5

def status
  @status
end