class Ilovepdf::ApiError
Attributes
http_response[RW]
Public Class Methods
new(http_response, custom_msg: nil)
click to toggle source
Calls superclass method
# File lib/ilovepdf/errors.rb, line 8 def initialize(http_response, custom_msg: nil) msg_to_use = custom_msg ? custom_msg : extract_error_text(http_response) super(msg_to_use) self.http_response = http_response end
Private Instance Methods
extract_error_text(http_response)
click to toggle source
# File lib/ilovepdf/errors.rb, line 15 def extract_error_text(http_response) r_body = http_response.body if r_body['name'] title = r_body['name'] msg = r_body['message'] elsif r_body['error'] title = r_body['error']['type'] msg = r_body['error']['message'] if r_body['error']['param'] msg << " Details: " + r_body['error']['param'].to_s end else title = 'An error ocurred' msg = 'Check the response from the server' end "[#{title}] #{msg}" end