-
-
Notifications
You must be signed in to change notification settings - Fork 25
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
push method and batch_push method error handling compatibility #13
Comments
Is there a clean way to extract error response messages? When using client = Fcmpush.new('sample-project')
puts client.batch_push(payloads).json.inspect
# this will print
# [{:name=>"projects/sample-project/messages/1702368289437197"}] # if success
# [{:error=>{:code=>400, :message=>"The registration token is not a valid FCM registration token", :status=>"INVALID_ARGUMENT", :details=>[{:@type=>"type.googleapis.com/google.firebase.fcm.v1.FcmError", :errorCode=>"INVALID_ARGUMENT"}]}}] # if invalid token But when using client = Fcmpush.new('sample-project')
puts client.push(payload).json.inspect
# this will print
# {:name=>"projects/sample-project/messages/1702368289437197"} # if success
# but raises an `Fcmpush::BadRequest` if token failed To extract the error response message, I have to: response =
begin
client.push(payload).json
rescue Fcmpush::BadRequest => e
JSON.parse(e.message.split(':', 2).last, :symbolize_names => true)
end
# where `response` will either contain
# {:name=>"projects/sample-project/messages/1702368289437197"} # if success
# {:error=>{:code=>400, :message=>"The registration token is not a valid FCM registration token", :status=>"INVALID_ARGUMENT", :details=>[{:@type=>"type.googleapis.com/google.firebase.fcm.v1.FcmError", :errorCode=>"INVALID_ARGUMENT"}]}} # if invalid token Is there a cleaner way to extract the error response message without The code in question: https://github.com/miyataka/fcmpush/blob/main/lib/fcmpush/client.rb#L141 Why am I doing this?I received an email from Firebase about Your recent usage of impacted APIs/features: Batch send API which will stop working on June 20, 2024. The official documentation suggests to just iterate the calls to HTTP V1:
Also according to: https://groups.google.com/g/firebase-talk/c/4GuTzvRT_10
So I'm migrating from To achieve the same output of payloads.map do |payload|
begin
client.push(payload).json
rescue Fcmpush::BadRequest => e
JSON.parse(e.message.split(':', 2).last, :symbolize_names => true)
end
end Thanks for the awesome library btw! |
@dcangulo, you can do this: begin
client.push(payload).json
rescue Fcmpush::BadRequest => e
JSON.parse(e.response.body)
end |
No description provided.
The text was updated successfully, but these errors were encountered: