Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix) Validation situations where Expo returns a 200 with an error #14

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions lib/exponent-server-sdk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ def handle_success(response)
end

def extract_data(response)
response.fetch('data').first
data_response = response.fetch('data')
return data_response.first if data_response.is_a? Array

data_response
end

def validate_status(status, response)
Expand Down Expand Up @@ -107,15 +110,15 @@ def with_error_handling(response)
end

def from_erroneous_response(response)
error = response.fetch('errors').first
error = extract_key(response, 'errors')
error_name = error.fetch('code')
message = error.fetch('message')

get_error_class(error_name).new(message)
end

def from_successful_response(response)
data = response.fetch('data').first
data = extract_key(response, 'data')
message = data.fetch('message')

get_error_class(data.fetch('details').fetch('error')).new(message)
Expand All @@ -134,6 +137,13 @@ def get_error_class(error_name)
def unknown_error_format(response)
Exponent::Push::UnknownError.new("Unknown error format: #{response}")
end

def extract_key(object, key)
key_response = object.fetch(key)
return key_response.first if key_response.is_a? Array

key_response
end
end

Error = Class.new(StandardError)
Expand Down