Skip to content
Merged
Show file tree
Hide file tree
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
18 changes: 16 additions & 2 deletions messaging/messaging.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,11 @@ type fcmResponse struct {

type fcmError struct {
Error struct {
Status string `json:"status"`
Status string `json:"status"`
Details []struct {
Type string `json:"@type"`
ErrorCode string `json:"errorCode"`
}
} `json:"error"`
}

Expand Down Expand Up @@ -422,7 +426,17 @@ func (c *Client) makeSendRequest(ctx context.Context, req *fcmRequest) (string,

var fe fcmError
json.Unmarshal(resp.Body, &fe) // ignore any json parse errors at this level
msg := fcmErrorCodes[fe.Error.Status]
var code string
for _, d := range fe.Error.Details {
if d.Type == "type.googleapis.com/google.firebase.fcm.v1.FcmErrorCode" {
code = d.ErrorCode
break
}
}
if code == "" {
code = fe.Error.Status
}
msg := fcmErrorCodes[code]
if msg == "" {
msg = fmt.Sprintf("server responded with an unknown error; response: %s", string(resp.Body))
}
Expand Down
5 changes: 5 additions & 0 deletions messaging/messaging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,11 @@ func TestSendError(t *testing.T) {
resp: "{\"error\": {\"status\": \"NOT_FOUND\", \"message\": \"test error\"}}",
want: "http error status: 500; reason: app instance has been unregistered; code: registration-token-not-registered",
},
{
resp: `{"error": {"status": "INVALID_ARGUMENT", "message": "test error", "details": [` +
`{"@type": "type.googleapis.com/google.firebase.fcm.v1.FcmErrorCode", "errorCode": "UNREGISTERED"}]}}`,
want: "http error status: 500; reason: app instance has been unregistered; code: registration-token-not-registered",
},
{
resp: "not json",
want: "http error status: 500; reason: server responded with an unknown error; response: not json",
Expand Down