@@ -8,46 +8,47 @@ import (
8
8
// Push notification error definitions
9
9
// This file contains all error types and messages used by the push notification system
10
10
11
+ // Error reason constants
12
+ const (
13
+ // HandlerReasons
14
+ ReasonHandlerNil = "handler cannot be nil"
15
+ ReasonHandlerExists = "cannot overwrite existing handler"
16
+ ReasonHandlerProtected = "handler is protected"
17
+
18
+ // ProcessorReasons
19
+ ReasonPushNotificationsDisabled = "push notifications are disabled"
20
+ )
21
+
11
22
// Common error variables for reuse
12
23
var (
13
24
// ErrHandlerNil is returned when attempting to register a nil handler
14
- ErrHandlerNil = errors .New ("handler cannot be nil" )
25
+ ErrHandlerNil = errors .New (ReasonHandlerNil )
15
26
)
16
27
17
28
// Registry errors
18
29
19
30
// ErrHandlerExists creates an error for when attempting to overwrite an existing handler
20
31
func ErrHandlerExists (pushNotificationName string ) error {
21
- return NewHandlerError ("register" , pushNotificationName , "cannot overwrite existing handler" , nil )
32
+ return NewHandlerError ("register" , pushNotificationName , ReasonHandlerExists , nil )
22
33
}
23
34
24
35
// ErrProtectedHandler creates an error for when attempting to unregister a protected handler
25
36
func ErrProtectedHandler (pushNotificationName string ) error {
26
- return NewHandlerError ("unregister" , pushNotificationName , "handler is protected" , nil )
37
+ return NewHandlerError ("unregister" , pushNotificationName , ReasonHandlerProtected , nil )
27
38
}
28
39
29
40
// VoidProcessor errors
30
41
31
42
// ErrVoidProcessorRegister creates an error for when attempting to register a handler on void processor
32
43
func ErrVoidProcessorRegister (pushNotificationName string ) error {
33
- return NewProcessorError ("void_processor" , "register" , pushNotificationName , "push notifications are disabled" , nil )
44
+ return NewProcessorError ("void_processor" , "register" , pushNotificationName , ReasonPushNotificationsDisabled , nil )
34
45
}
35
46
36
47
// ErrVoidProcessorUnregister creates an error for when attempting to unregister a handler on void processor
37
48
func ErrVoidProcessorUnregister (pushNotificationName string ) error {
38
- return NewProcessorError ("void_processor" , "unregister" , pushNotificationName , "push notifications are disabled" , nil )
49
+ return NewProcessorError ("void_processor" , "unregister" , pushNotificationName , ReasonPushNotificationsDisabled , nil )
39
50
}
40
51
41
- // Error message constants for consistency
42
- const (
43
- // Error message templates
44
- MsgHandlerNil = "handler cannot be nil"
45
- MsgHandlerExists = "cannot overwrite existing handler for push notification: %s"
46
- MsgProtectedHandler = "cannot unregister protected handler for push notification: %s"
47
- MsgVoidProcessorRegister = "cannot register push notification handler '%s': push notifications are disabled (using void processor)"
48
- MsgVoidProcessorUnregister = "cannot unregister push notification handler '%s': push notifications are disabled (using void processor)"
49
- )
50
-
51
52
// Error type definitions for advanced error handling
52
53
53
54
// HandlerError represents errors related to handler operations
@@ -124,23 +125,23 @@ func IsHandlerNilError(err error) bool {
124
125
// IsHandlerExistsError checks if an error is due to attempting to overwrite an existing handler
125
126
func IsHandlerExistsError (err error ) bool {
126
127
if handlerErr , ok := err .(* HandlerError ); ok {
127
- return handlerErr .Operation == "register" && handlerErr .Reason == "cannot overwrite existing handler"
128
+ return handlerErr .Operation == "register" && handlerErr .Reason == ReasonHandlerExists
128
129
}
129
130
return false
130
131
}
131
132
132
133
// IsProtectedHandlerError checks if an error is due to attempting to unregister a protected handler
133
134
func IsProtectedHandlerError (err error ) bool {
134
135
if handlerErr , ok := err .(* HandlerError ); ok {
135
- return handlerErr .Operation == "unregister" && handlerErr .Reason == "handler is protected"
136
+ return handlerErr .Operation == "unregister" && handlerErr .Reason == ReasonHandlerProtected
136
137
}
137
138
return false
138
139
}
139
140
140
141
// IsVoidProcessorError checks if an error is due to void processor operations
141
142
func IsVoidProcessorError (err error ) bool {
142
143
if procErr , ok := err .(* ProcessorError ); ok {
143
- return procErr .ProcessorType == "void_processor" && procErr .Reason == "push notifications are disabled"
144
+ return procErr .ProcessorType == "void_processor" && procErr .Reason == ReasonPushNotificationsDisabled
144
145
}
145
146
return false
146
147
}
0 commit comments