Skip to content

Conversation

hiranya911
Copy link
Contributor

This PR improves error handling in the SDK by providing explicit functions that test for various error codes:

firebase.google.com/go/messaging
  func IsInternal(err error) bool
  func IsInvalidAPNSCredentials(err error) bool
  func IsInvalidArgument(err error) bool
  func IsMessageRateExceeded(err error) bool
  func IsMismatchedCredential(err error) bool
  func IsRegistrationTokenNotRegistered(err error) bool
  func IsServerUnavailable(err error) bool
  func IsTooManyTopics(err error) bool
  func IsUnknown(err error) bool
firebase.google.com/go/auth
  func IsEmailAlreadyExists(err error) bool
  func IsIDTokenRevoked(err error) bool
  func IsInsufficientPermission(err error) bool
  func IsPhoneNumberAlreadyExists(err error) bool
  func IsProjectNotFound(err error) bool
  func IsUIDAlreadyExists(err error) bool
  func IsUnknown(err error) bool
  func IsUserNotFound(err error) bool

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@hiranya911 hiranya911 changed the base branch from master to dev April 10, 2018 18:19
@hiranya911 hiranya911 requested a review from bklimt April 10, 2018 18:20
@@ -345,10 +349,7 @@ func processClaims(p map[string]interface{}) error {
return nil
}

claims, ok := cc.(map[string]interface{})
if !ok {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure you don't want to leave some kind of error reported here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is guaranteed to be a map since we have typed functions for setting custom claims (SetCustomClaims() for instance).

auth/user_mgt.go Outdated
"PROJECT_NOT_FOUND": projectNotFound,
}

func handleServerError(err error) *internal.FirebaseError {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably use error for the return type here, just because I've been bitten too many times by trying to use a specific error type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. Done

if !ok {
clientCode = unknown
}
return internal.Error(clientCode, err.Error())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this might get called in cases where the error is generated on the client by a failure to connect or something. Do we want to always wrap error in our own type like this, possibly losing original error data other than the string? Or should we just pass on errors that aren't from the backend as-is? This is something I've been thinking about a lot on all of our SDKs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. We shouldn't be wrapping non-backend errors. Updated the implementation.

// If the error does not contain an error code, this function returns an empty string. Use this
// internal function for unit tests in packages that cannot directly import the root firebase
// package.
func Code(err error) string {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this isn't actually used anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

@hiranya911 hiranya911 assigned hiranya911 and unassigned bklimt Apr 10, 2018
@hiranya911 hiranya911 merged commit 0beafb8 into dev Apr 10, 2018
@hiranya911 hiranya911 deleted the hkj-error-codes branch April 10, 2018 22:34
hiranya911 added a commit that referenced this pull request Apr 17, 2018
* Changlog updates (#123)

* Reading FCM error code from details section (#127)

* Adding additional details to the error message when available (#129)

* Implementing support for APNS content-mutable field (#126)

* Implementing support for APNS content-mutable field

* Corrected the mutable-content option name

* Renamed CustomFields to CustomData

* Added comment

* Implementing Functions to Test Error Codes (#131)

* Adding error codes to the auth package

* Added error codes for messaging

* Responding to review feedback; Updated changelog

* Add Go import comments. (#132)

* Bumped version to 2.7.0 (#133)

* Bumped version to 2.7.0

* Updated changelog
hiranya911 added a commit that referenced this pull request Jun 12, 2018
* Adding error codes to the auth package

* Added error codes for messaging

* Responding to review feedback; Updated changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants