firebase / firebase/firebase-admin-go
FR: [FB Messaging] Expose full FirebaseError
- Dominant language
- Go
- Stars
- 1.3k
- Forks
- 274
- Avg merge
- 10h 39m
- Merged PRs (30d)
- 2
Description
### [REQUIRED] Step 2: Describe your environment
* Operating System version: macOS
* Firebase SDK version: latest
* Library version: v4.12.0
* Firebase Product: messaging
### [REQUIRED] Step 3: Describe the problem
#### Steps to reproduce:
The messaging api returns robust error codes to tell your application what went wrong with the server. This go-lang library abstracts this away and only gives you the following struct: https://github.com/firebase/firebase-admin-go/blob/v4.12.0/messaging/messaging_batch.go#L78
This makes it impossible to react to different kinds of failures when calling `sendBatch`. In my case, I want to remove invalid device tokens from my database.
If the lib could return this struct (https://github.com/firebase/firebase-admin-go/blob/74c9bd5edece6044ba365a04c32c00074006dd7c/internal/errors.go#L87) instead of the standard error the issue would be resolved.
#### Relevant Code:
```go
func (firebaseSender *FirebaseSender) cleanupDevices(ctx context.Context, batchResponse *messaging.BatchResponse) {
if batchResponse.FailureCount == 0 {
return
}
for _, sendResponse := range batchResponse.Responses {
logger.Debug(sendResponse.Error) // Expose ErrorCode here so that I can switch and deal with different kinds of failures.
}
}
```
The internal library has the data structure I need, but it is in the internal library and unavailable to other modules.
```go
// ErrorCode represents the platform-wide error codes that can be raised by
// Admin SDK APIs.
type ErrorCode string
const (
// InvalidArgument is a OnePlatform error code.
InvalidArgument ErrorCode = "INVALID_ARGUMENT"
// FailedPrecondition is a OnePlatform error code.
FailedPrecondition ErrorCode = "FAILED_PRECONDITION"
// OutOfRange is a OnePlatform error code.
OutOfRange ErrorCode = "OUT_OF_RANGE"
// Unauthenticated is a OnePlatform error code.
Unauthenticated ErrorCode = "UNAUTHENTICATED"
// PermissionDenied is a OnePlatform error code.
PermissionDenied ErrorCode = "PERMISSION_DENIED"
// NotFound is a OnePlatform error code.
NotFound ErrorCode = "NOT_FOUND"
// Conflict is a custom error code that represents HTTP 409 responses.
//
// OnePlatform APIs typically respond with ABORTED or ALREADY_EXISTS explicitly. But a few
// old APIs send HTTP 409 Conflict without any additional details to distinguish between the two
// cases. For these we currently use this error code. As more APIs adopt OnePlatform conventions
// this will become less important.
Conflict ErrorCode = "CONFLICT"
// Aborted is a OnePlatform error code.
Aborted ErrorCode = "ABORTED"
// AlreadyExists is a OnePlatform error code.
AlreadyExists ErrorCode = "ALREADY_EXISTS"
// ResourceExhausted is a OnePlatform error code.
ResourceExhausted ErrorCode = "RESOURCE_EXHAUSTED"
// Cancelled is a OnePlatform error code.
Cancelled ErrorCode = "CANCELLED"
// DataLoss is a OnePlatform error code.
DataLoss ErrorCode = "DATA_LOSS"
// Unknown is a OnePlatform error code.
Unknown ErrorCode = "UNKNOWN"
// Internal is a OnePlatform error code.
Internal ErrorCode = "INTERNAL"
// Unavailable is a OnePlatform error code.
Unavailable ErrorCode = "UNAVAILABLE"
// DeadlineExceeded is a OnePlatform error code.
DeadlineExceeded ErrorCode = "DEADLINE_EXCEEDED"
)
// FirebaseError is an error type containing an error code string.
type FirebaseError struct {
ErrorCode ErrorCode
String string
Response *http.Response
Ext map[string]interface{}
}
func (fe *FirebaseError) Error() string {
return fe.String
}
```
Contributor guide
Assessment
This issue has not been assessed yet.