Exception: Mautic::RequestError
- Inherits:
-
StandardError
- Object
- StandardError
- Mautic::RequestError
- Defined in:
- lib/mautic.rb
Direct Known Subclasses
AuthorizeError, RecordNotFound, TokenExpiredError, ValidationError
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#request_url ⇒ Object
readonly
Returns the value of attribute request_url.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#initialize(response, message = nil) ⇒ RequestError
constructor
A new instance of RequestError.
Constructor Details
#initialize(response, message = nil) ⇒ RequestError
Returns a new instance of RequestError.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mautic.rb', line 16 def initialize(response, = nil) @errors ||= [] @response = response @request_url = response.response&.env&.url body = if response.body.start_with? "<!DOCTYPE html>" response.body.split("\n").last else response.body end json_body = begin JSON.parse(body) rescue JSON::ParserError { "errors" => [{ "code" => response.status, "message" => body }] } end ||= Array(json_body['errors']).collect do |error| msg = error['code'].to_s msg << " (#{error['type']}):" if error['type'] msg << " #{error['message']}" @errors << error['message'] msg end.join(', ') super("#{@request_url} => #{}") end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
14 15 16 |
# File 'lib/mautic.rb', line 14 def errors @errors end |
#request_url ⇒ Object (readonly)
Returns the value of attribute request_url.
14 15 16 |
# File 'lib/mautic.rb', line 14 def request_url @request_url end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
14 15 16 |
# File 'lib/mautic.rb', line 14 def response @response end |