diff --git a/fcm.go b/fcm.go index bf46a3d..a925be4 100644 --- a/fcm.go +++ b/fcm.go @@ -110,11 +110,9 @@ func (f *FCM) Send(message Message) (Response, error) { // Failed method indicates if the server couldn't process // the request in time. func (f *FCM) Failed(response *Response) error { - for _, val := range response.Results { - for k, v := range val { - if k == ErrorKey && retryableErrors[v] { - return fmt.Errorf("Failed %s", k) - } + for _, response := range response.Results { + if retryableErrors[response.Error] { + return fmt.Errorf("Failed %s", response.Error) } } diff --git a/models.go b/models.go index aca253f..b3528ac 100644 --- a/models.go +++ b/models.go @@ -94,6 +94,23 @@ type ( Condition string `json:"condition,omitempty"` } + // Downstream result from FCM, sent in the "results" field of the Response packet + Result struct { + // String specifying a unique ID for each successfully processed message. + MessageID string `json:"message_id"` + + // Optional string specifying the canonical registration token for the + // client app that the message was processed and sent to. Sender should + // use this value as the registration token for future requests. + // Otherwise, the messages might be rejected. + RegistrationID string `json:"registration_id"` + + // String specifying the error that occurred when processing the message + // for the recipient. The possible values can be found in table 9 here: + // https://firebase.google.com/docs/cloud-messaging/http-server-ref#table9 + Error string `json:"error"` + } + // Response represents fcm response message - (tokens and topics) Response struct { Ok bool @@ -118,7 +135,7 @@ type ( // message_id: String specifying a unique ID for each successfully processed message. // registration_id: Optional string specifying the canonical registration token for the client app that the message was processed and sent to. Sender should use this value as the registration token for future requests. Otherwise, the messages might be rejected. // error: String specifying the error that occurred when processing the message for the recipient. The possible values can be found in table 9. - Results []map[string]string `json:"results,omitempty"` + Results []Result `json:"results,omitempty"` // The topic message ID when FCM has successfully received the request and will attempt to deliver to all subscribed devices. MsgID int `json:"message_id,omitempty"`