class LineChange::APIError

API errors

Attributes

body[R]
headers[R]
status[R]

Public Class Methods

new(args) click to toggle source
Calls superclass method
# File lib/line_change/errors.rb, line 8
def initialize(args)
  @status, @headers, @body = args[:status], args[:headers], parse_json(args[:body])

  message =
    body['message'] ||
    (body['errors'] && convert_hash_to_message(body['errors'])) ||
    body

  super(message)
end

Private Instance Methods

convert_hash_to_message(hash) click to toggle source
# File lib/line_change/errors.rb, line 27
def convert_hash_to_message(hash)
  hash.map{|_| _.join(' ').capitalize }.join('. ')
end
parse_json(body) click to toggle source
# File lib/line_change/errors.rb, line 21
def parse_json(body)
  JSON.parse(body.to_s)
rescue JSON::ParserError
  body
end