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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Unreleased

- [changed] Improved error handling in FCM by mapping more server-side
errors to client-side error codes.
- [added] Added the `db` package for interacting with the Firebase database.

# v2.5.0
Expand Down
15 changes: 11 additions & 4 deletions messaging/messaging.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,20 @@ var (
topicNamePattern = regexp.MustCompile("^(/topics/)?(private/)?[a-zA-Z0-9-_.~%]+$")

fcmErrorCodes = map[string]string{
// FCM v1 canonical error codes
"NOT_FOUND": "app instance has been unregistered; code: registration-token-not-registered",
"PERMISSION_DENIED": "sender id does not match regisration token; code: mismatched-credential",
"RESOURCE_EXHAUSTED": "messaging service quota exceeded; code: message-rate-exceeded",
"UNAUTHENTICATED": "apns certificate or auth key was invalid; code: invalid-apns-credentials",

// FCM v1 new error codes
"APNS_AUTH_ERROR": "apns certificate or auth key was invalid; code: invalid-apns-credentials",
"INTERNAL": "back servers encountered an unknown internl error; code: internal-error",
"INVALID_ARGUMENT": "request contains an invalid argument; code: invalid-argument",
"UNREGISTERED": "app instance has been unregistered; code: registration-token-not-registered",
"SENDER_ID_MISMATCH": "sender id does not match regisration token; code: authentication-error",
"SENDER_ID_MISMATCH": "sender id does not match regisration token; code: mismatched-credential",
"QUOTA_EXCEEDED": "messaging service quota exceeded; code: message-rate-exceeded",
"APNS_AUTH_ERROR": "apns certificate or auth key was invalid; code: authentication-error",
"UNAVAILABLE": "backend servers are temporarily unavailable; code: server-unavailable",
"INTERNAL": "back servers encountered an unknown internl error; code: internal-error",
"UNREGISTERED": "app instance has been unregistered; code: registration-token-not-registered",
}

iidErrorCodes = map[string]string{
Expand Down
4 changes: 4 additions & 0 deletions messaging/messaging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,10 @@ 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",
},
{
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: "not json",
want: "http error status: 500; reason: server responded with an unknown error; response: not json",
Expand Down