This repository has been archived by the owner on Feb 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
77 lines (66 loc) · 2.34 KB
/
error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package gcmlib
import "fmt"
// Error
type gcmError struct {
code gcmErrorCode
message string
}
func (e *gcmError) Error() string {
return fmt.Sprintf("%s: %s", e.code.String(), e.message)
}
func (e *gcmError) ShouldRetry() bool {
return e.code == ErrorConnection || e.code == ErrorServiceUnavailable
}
func (e *gcmError) Code() gcmErrorCode {
return e.code
}
func newError(errorCode gcmErrorCode, message string) *gcmError {
return &gcmError{code: errorCode, message: message}
}
type gcmErrorCode int
// Errors
const (
ErrorUnknown gcmErrorCode = 1
ErrorBadRequest gcmErrorCode = 400
ErrorAuthentication gcmErrorCode = 401
ErrorRequestEntityTooLarge gcmErrorCode = 413
ErrorServiceUnavailable gcmErrorCode = 500
ErrorResponseParse gcmErrorCode = 1000
ErrorConnection gcmErrorCode = 1001
)
func (t gcmErrorCode) String() string {
switch t {
case ErrorBadRequest:
return "bad request"
case ErrorAuthentication:
return "authentication error"
case ErrorRequestEntityTooLarge:
return "request entity too large"
case ErrorServiceUnavailable:
return "gcm service unavailable"
case ErrorResponseParse:
return "response body is not well-formed json"
case ErrorConnection:
return "connection error"
default:
return "unknown error"
}
}
type resultError string
// Result-level error codes can be found in response.Results for each individual
// recipient.
// See https://developers.google.com/cloud-messaging/server-ref#error-codes
const (
ResultErrorMissingRegistration resultError = "MissingRegistration"
ResultErrorInvalidRegistration resultError = "InvalidRegistration"
ResultErrorNotRegistered resultError = "NotRegistered"
ResultErrorMessageTooBig resultError = "MessageTooBig"
ResultErrorInvalidDataKey resultError = "InvalidDataKey"
ResultErrorInvalidTTL resultError = "InvalidTtl"
ResultErrorDeviceMessageRateExceeded resultError = "DeviceMessageRateExceeded"
ResultErrorTopicsMessageRateExceeded resultError = "TopicsMessageRateExceeded"
ResultErrorMismatchSenderID resultError = "MismatchSenderId"
ResultErrorInvalidPackageName resultError = "InvalidPackageName"
ResultErrorInternalServerError resultError = "InternalServerError"
ResultErrorUnavailable resultError = "Unavailable"
)