class Sendgrid::API::REST::Errors::Error

Public Class Methods

from_response(env) click to toggle source
# File lib/sendgrid/api/rest/errors/error.rb, line 10
def from_response(env)
  status_error(env) || body_error(env)
end

Private Class Methods

body_error(env) click to toggle source
# File lib/sendgrid/api/rest/errors/error.rb, line 27
def body_error(env)
  body = env[:body]
  if body.is_a?(Hash) && body.has_key?(:error)
    status, message = case body[:error]
                      when ::Hash
                        [ body[:error][:code], body[:error][:message] ]
                      when ::String
                        [ 422, body[:error] ]
                      end
    error_class(status).new(message)
  else
    nil
  end
end
error_class(status) click to toggle source
# File lib/sendgrid/api/rest/errors/error.rb, line 42
def error_class(status)
  Errors::CODES[status] || Errors::Unknown
end
status_error(env) click to toggle source
# File lib/sendgrid/api/rest/errors/error.rb, line 16
def status_error(env)
  body = env[:body]
  status = env[:status].to_i
  if status != 200
    message = body[:error] || body[:errors].join(', ') if body.is_a?(Hash)
    error_class(status).new(message)
  else
    nil
  end
end