class Mautic::RequestError
Attributes
errors[R]
request_url[R]
response[R]
Public Class Methods
new(response, message = nil)
click to toggle source
Calls superclass method
# File lib/mautic.rb, line 16 def initialize(response, message = 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 message ||= 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} => #{message}") end