Exception: Mistral::APIError

Inherits:
Error
  • Object
show all
Defined in:
lib/mistral/exceptions.rb

Direct Known Subclasses

APIStatusError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message: nil, http_status: nil, headers: nil) ⇒ APIError

Returns a new instance of APIError.



11
12
13
14
15
16
# File 'lib/mistral/exceptions.rb', line 11

def initialize(message: nil, http_status: nil, headers: nil)
  super(message: message)

  @http_status = http_status
  @headers = headers
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



9
10
11
# File 'lib/mistral/exceptions.rb', line 9

def headers
  @headers
end

#http_statusObject (readonly)

Returns the value of attribute http_status.



9
10
11
# File 'lib/mistral/exceptions.rb', line 9

def http_status
  @http_status
end

Class Method Details

.from_response(response, message: nil) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/mistral/exceptions.rb', line 18

def self.from_response(response, message: nil)
  new(
    message: message || response.to_s,
    http_status: response.code,
    headers: response.headers.to_h
  )
end

Instance Method Details

#to_sObject



26
27
28
# File 'lib/mistral/exceptions.rb', line 26

def to_s
  "#{self.class.name}(message=#{super}, http_status=#{http_status})"
end