class Exponent::Push::ErrorBuilder

Public Instance Methods

parse_push_ticket(push_ticket) click to toggle source
# File lib/exponent-server-sdk.rb, line 247
def parse_push_ticket(push_ticket)
  with_error_handling(push_ticket) do
    message = push_ticket.fetch('message')
    get_error_class(push_ticket.fetch('details').fetch('error')).new(message)
  end
end
parse_response(response) click to toggle source
# File lib/exponent-server-sdk.rb, line 237
def parse_response(response)
  with_error_handling(response) do
    error      = response.fetch('errors')
    error_name = error.fetch('code')
    message    = error.fetch('message')

    get_error_class(error_name).new(message)
  end
end

Private Instance Methods

from_erroneous_response(response) click to toggle source

@deprecated

# File lib/exponent-server-sdk.rb, line 287
def from_erroneous_response(response)
  error      = response.fetch('errors').first
  error_name = error.fetch('code')
  message    = error.fetch('message')

  get_error_class(error_name).new(message)
end
from_successful_response(response) click to toggle source

@deprecated

# File lib/exponent-server-sdk.rb, line 296
def from_successful_response(response)
  delivery_result = response.fetch('data').first
  message         = delivery_result.fetch('message')
  get_error_class(delivery_result.fetch('details').fetch('error')).new(message)
end
get_error_class(error_name) click to toggle source
# File lib/exponent-server-sdk.rb, line 274
def get_error_class(error_name)
  validate_error_name(Exponent::Push.error_names.include?(error_name)) do
    Exponent::Push.const_get("#{error_name}Error")
  end
end
unknown_error_format(response) click to toggle source
# File lib/exponent-server-sdk.rb, line 280
def unknown_error_format(response)
  Exponent::Push::UnknownError.new("Unknown error format: #{response}")
end
validate_error_name(condition) { |: UnknownError| ... } click to toggle source
# File lib/exponent-server-sdk.rb, line 270
def validate_error_name(condition)
  condition ? yield : Exponent::Push::UnknownError
end
with_error_handling(response) { |response| ... } click to toggle source
# File lib/exponent-server-sdk.rb, line 264
def with_error_handling(response)
  yield(response)
rescue KeyError, NoMethodError
  unknown_error_format(response)
end