Exception: Fopost::Error

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

Overview

Base class for every error the FoPost API returns.

The API answers failures with an {"error": "<code>", "message": "<human readable>"} envelope, which maps onto #code and #message.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, status:, code: nil, body: nil) ⇒ Error

Returns a new instance of Error.



15
16
17
18
19
20
21
# File 'lib/fopost/errors.rb', line 15

def initialize(message, status:, code: nil, body: nil)
  super(message)
  @message = message
  @status = status
  @code = code
  @body = body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



9
10
11
# File 'lib/fopost/errors.rb', line 9

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



9
10
11
# File 'lib/fopost/errors.rb', line 9

def code
  @code
end

#messageObject (readonly)

The message the API sent, undecorated. to_s adds the status and code, so an uncaught error still reports both.



13
14
15
# File 'lib/fopost/errors.rb', line 13

def message
  @message
end

#statusObject (readonly)

Returns the value of attribute status.



9
10
11
# File 'lib/fopost/errors.rb', line 9

def status
  @status
end

Instance Method Details

#to_sObject



23
24
25
26
# File 'lib/fopost/errors.rb', line 23

def to_s
  suffix = code ? " (#{code})" : ''
  "[#{status}#{suffix}] #{@message}"
end