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
3 changes: 3 additions & 0 deletions messaging/messaging.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ type fcmResponse struct {
type fcmError struct {
Error struct {
Status string `json:"status"`
Message string `json:"message"`
Details []struct {
Type string `json:"@type"`
ErrorCode string `json:"errorCode"`
Expand Down Expand Up @@ -439,6 +440,8 @@ func (c *Client) makeSendRequest(ctx context.Context, req *fcmRequest) (string,
msg := fcmErrorCodes[code]
if msg == "" {
msg = fmt.Sprintf("server responded with an unknown error; response: %s", string(resp.Body))
} else if fe.Error.Message != "" {
msg += "; details: " + fe.Error.Message
}
return "", fmt.Errorf("http error status: %d; reason: %s", resp.Status, msg)
}
Expand Down
8 changes: 5 additions & 3 deletions messaging/messaging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,16 +627,18 @@ func TestSendError(t *testing.T) {
},
{
resp: "{\"error\": {\"status\": \"INVALID_ARGUMENT\", \"message\": \"test error\"}}",
want: "http error status: 500; reason: request contains an invalid argument; code: invalid-argument",
want: "http error status: 500; reason: request contains an invalid argument; code: invalid-argument; details: test error",
},
{
resp: "{\"error\": {\"status\": \"NOT_FOUND\", \"message\": \"test error\"}}",
want: "http error status: 500; reason: app instance has been unregistered; code: registration-token-not-registered",
want: "http error status: 500; reason: app instance has been unregistered; code: registration-token-not-registered; " +
"details: test error",
},
{
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",
want: "http error status: 500; reason: app instance has been unregistered; code: registration-token-not-registered; " +
"details: test error",
},
{
resp: "not json",
Expand Down