Exception: Mistri::ProviderError

Inherits:
Error
  • Object
show all
Defined in:
lib/mistri/errors.rb

Overview

A provider request failed. Carries the HTTP status and response body when the transport got that far.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, status: nil, body: nil) ⇒ ProviderError

Returns a new instance of ProviderError.



19
20
21
22
23
# File 'lib/mistri/errors.rb', line 19

def initialize(message = nil, status: nil, body: nil)
  @status = status
  @body = body
  super(message || self.class.default_message)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



17
18
19
# File 'lib/mistri/errors.rb', line 17

def body
  @body
end

#statusObject (readonly)

Returns the value of attribute status.



17
18
19
# File 'lib/mistri/errors.rb', line 17

def status
  @status
end

Class Method Details

.default_messageObject



34
# File 'lib/mistri/errors.rb', line 34

def self.default_message = "provider request failed"

Instance Method Details

#describeObject

The full story for logs and error turns: the response names the fix far more often than the status line does.



27
28
29
30
31
32
# File 'lib/mistri/errors.rb', line 27

def describe
  parts = [message]
  parts << "status #{status}" if status
  parts << body.to_s[0, 300] if body && !body.to_s.strip.empty?
  parts.join(" | ")
end