class WorkSnaps::Error::ClientError

Raised when WorkSnaps returns a 4xx HTTP status code or there's an error in Faraday

Public Class Methods

from_response(response={}) click to toggle source

Create a new error from an HTTP environment

@param response [Hash] @return [WorkSnaps::Error]

# File lib/worksnaps/error/client_error.rb, line 12
def self.from_response(response={})
  new(parse_error(response[:body]), response[:response_headers])
end

Private Class Methods

parse_error(body) click to toggle source
# File lib/worksnaps/error/client_error.rb, line 18
def self.parse_error(body)
  if body.nil?
    ''
  elsif body[:error]
    body[:error]
  elsif body[:errors]
    first = Array(body[:errors]).first
    if first.is_a?(Hash)
      first[:message].chomp
    else
      first.chomp
    end
  end
end