Exception: JaLC::REST::HTTPError

Inherits:
Error
  • Object
show all
Defined in:
lib/jalc/rest/middleware/raise_error.rb

Direct Known Subclasses

ClientError, ServerError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg = nil, response: nil) ⇒ HTTPError

Returns a new instance of HTTPError.



45
46
47
48
49
50
51
# File 'lib/jalc/rest/middleware/raise_error.rb', line 45

def initialize(msg = nil, response: nil)
  @response = response
  msg ||= response[:body].dig('message', 'errors', 'message') if response && response[:body].is_a?(Hash)
  msg ||= "the server responded with status #{response[:status]}" if response

  super(msg)
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



43
44
45
# File 'lib/jalc/rest/middleware/raise_error.rb', line 43

def response
  @response
end

Instance Method Details

#inspectObject



53
54
55
56
57
58
59
# File 'lib/jalc/rest/middleware/raise_error.rb', line 53

def inspect
  if response
    %(#<#{self.class} response=#{response.inspect}>)
  else
    super
  end
end