Exception: XxxRename::SiteClients::Errors::APIError

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint:, code:, body:, headers:) ⇒ APIError

Returns a new instance of APIError.



69
70
71
72
73
74
75
# File 'lib/xxx_rename/site_clients/errors.rb', line 69

def initialize(endpoint:, code:, body:, headers:)
  @endpoint = endpoint
  @code = code
  @body = body
  @headers = headers
  super(message)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



67
68
69
# File 'lib/xxx_rename/site_clients/errors.rb', line 67

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



67
68
69
# File 'lib/xxx_rename/site_clients/errors.rb', line 67

def code
  @code
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



67
68
69
# File 'lib/xxx_rename/site_clients/errors.rb', line 67

def endpoint
  @endpoint
end

#headersObject (readonly)

Returns the value of attribute headers.



67
68
69
# File 'lib/xxx_rename/site_clients/errors.rb', line 67

def headers
  @headers
end

Instance Method Details

#fetch_error_messageObject



77
78
79
80
81
82
# File 'lib/xxx_rename/site_clients/errors.rb', line 77

def fetch_error_message
  case code
  when 302 then "unexpected redirection to #{headers["location"]}"
  else (body&.[]("error") || body&.[]("message") || body).to_s[0..150]
  end
end

#messageObject



84
85
86
87
88
89
# File 'lib/xxx_rename/site_clients/errors.rb', line 84

def message
  "API Failure:\n" \
  "\tURL: #{endpoint}\n" \
  "\tRESPONSE CODE: #{code}\n" \
  "\tERROR MESSAGE: #{fetch_error_message}"
end