class PCO::API::Errors::BaseError

Attributes

detail[R]
headers[R]
status[R]

Public Class Methods

new(response) click to toggle source
# File lib/pco/api/errors.rb, line 9
def initialize(response)
  @status = response.status
  @detail = response.body
  @headers = response.headers
end

Public Instance Methods

inspect() click to toggle source
# File lib/pco/api/errors.rb, line 24
def inspect
  "<#{self.class.name} status=#{status} message=#{message.inspect} detail=#{detail.inspect}>"
end
message() click to toggle source
# File lib/pco/api/errors.rb, line 19
def message
  return detail.to_s unless detail.is_a?(Hash)
  detail['message'] || validation_message || detail.to_s
end
to_s() click to toggle source
# File lib/pco/api/errors.rb, line 15
def to_s
  message
end

Private Instance Methods

error_to_string(error) click to toggle source
# File lib/pco/api/errors.rb, line 38
def error_to_string(error)
  return unless error.is_a?(Hash)
  [
    "#{error['title']}:",
    error.fetch('meta', {})['resource'],
    error.fetch('source', {})['parameter'],
    error['detail']
  ].compact.join(' ')
end
validation_message() click to toggle source
# File lib/pco/api/errors.rb, line 30
def validation_message
  return if Array(detail['errors']).empty?
  errors = detail['errors'].map do |error|
    error_to_string(error)
  end
  errors.uniq.join('; ')
end