Exception: Pluggy::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/pluggy/errors.rb

Overview

Flat, one-level hierarchy off a single base carrying the whole HTTP transcript. Unlike Stripe there is no request id: the Pluggy spec documents zero response headers, so nothing reliable exists to capture.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, http_status: nil, http_body: nil, http_headers: nil, json_body: nil) ⇒ Error

Returns a new instance of Error.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pluggy/errors.rb', line 11

def initialize(message = nil, http_status: nil, http_body: nil, http_headers: nil, json_body: nil)
  @http_status = http_status
  @http_body = http_body
  @http_headers = http_headers || {}
  @json_body = json_body

  if json_body.is_a?(Hash)
    @code = json_body["code"]
    @code_description = json_body["codeDescription"]
    @data = json_body["data"]
  end

  # The API's own text, undecorated. #message and #to_s append the
  # codeDescription because that is what you want in a log line; this is
  # here for when you want to render just the message.
  @api_message = message || @json_body&.fetch("message", nil) || default_message

  super(@api_message)
end

Instance Attribute Details

#api_messageObject (readonly)

Returns the value of attribute api_message.



8
9
10
# File 'lib/pluggy/errors.rb', line 8

def api_message
  @api_message
end

#codeObject (readonly)

Returns the value of attribute code.



8
9
10
# File 'lib/pluggy/errors.rb', line 8

def code
  @code
end

#code_descriptionObject (readonly)

Returns the value of attribute code_description.



8
9
10
# File 'lib/pluggy/errors.rb', line 8

def code_description
  @code_description
end

#dataObject (readonly)

Returns the value of attribute data.



8
9
10
# File 'lib/pluggy/errors.rb', line 8

def data
  @data
end

#http_bodyObject (readonly)

Returns the value of attribute http_body.



8
9
10
# File 'lib/pluggy/errors.rb', line 8

def http_body
  @http_body
end

#http_headersObject (readonly)

Returns the value of attribute http_headers.



8
9
10
# File 'lib/pluggy/errors.rb', line 8

def http_headers
  @http_headers
end

#http_statusObject (readonly)

Returns the value of attribute http_status.



8
9
10
# File 'lib/pluggy/errors.rb', line 8

def http_status
  @http_status
end

#json_bodyObject (readonly)

Returns the value of attribute json_body.



8
9
10
# File 'lib/pluggy/errors.rb', line 8

def json_body
  @json_body
end

Instance Method Details

#to_sObject



31
32
33
# File 'lib/pluggy/errors.rb', line 31

def to_s
  @code_description ? "#{@api_message} (#{@code_description})" : @api_message
end