diff --git a/messaging/messaging.go b/messaging/messaging.go index b4c31c7b..51782f60 100644 --- a/messaging/messaging.go +++ b/messaging/messaging.go @@ -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"` @@ -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) } diff --git a/messaging/messaging_test.go b/messaging/messaging_test.go index 8a39ffc6..8839a0be 100644 --- a/messaging/messaging_test.go +++ b/messaging/messaging_test.go @@ -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",