@@ -8,46 +8,47 @@ import (
88// Push notification error definitions
99// This file contains all error types and messages used by the push notification system
1010
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+
1122// Common error variables for reuse
1223var (
1324 // ErrHandlerNil is returned when attempting to register a nil handler
14- ErrHandlerNil = errors .New ("handler cannot be nil" )
25+ ErrHandlerNil = errors .New (ReasonHandlerNil )
1526)
1627
1728// Registry errors
1829
1930// ErrHandlerExists creates an error for when attempting to overwrite an existing handler
2031func ErrHandlerExists (pushNotificationName string ) error {
21- return NewHandlerError ("register" , pushNotificationName , "cannot overwrite existing handler" , nil )
32+ return NewHandlerError ("register" , pushNotificationName , ReasonHandlerExists , nil )
2233}
2334
2435// ErrProtectedHandler creates an error for when attempting to unregister a protected handler
2536func ErrProtectedHandler (pushNotificationName string ) error {
26- return NewHandlerError ("unregister" , pushNotificationName , "handler is protected" , nil )
37+ return NewHandlerError ("unregister" , pushNotificationName , ReasonHandlerProtected , nil )
2738}
2839
2940// VoidProcessor errors
3041
3142// ErrVoidProcessorRegister creates an error for when attempting to register a handler on void processor
3243func 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 )
3445}
3546
3647// ErrVoidProcessorUnregister creates an error for when attempting to unregister a handler on void processor
3748func 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 )
3950}
4051
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-
5152// Error type definitions for advanced error handling
5253
5354// HandlerError represents errors related to handler operations
@@ -124,23 +125,23 @@ func IsHandlerNilError(err error) bool {
124125// IsHandlerExistsError checks if an error is due to attempting to overwrite an existing handler
125126func IsHandlerExistsError (err error ) bool {
126127 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
128129 }
129130 return false
130131}
131132
132133// IsProtectedHandlerError checks if an error is due to attempting to unregister a protected handler
133134func IsProtectedHandlerError (err error ) bool {
134135 if handlerErr , ok := err .(* HandlerError ); ok {
135- return handlerErr .Operation == "unregister" && handlerErr .Reason == "handler is protected"
136+ return handlerErr .Operation == "unregister" && handlerErr .Reason == ReasonHandlerProtected
136137 }
137138 return false
138139}
139140
140141// IsVoidProcessorError checks if an error is due to void processor operations
141142func IsVoidProcessorError (err error ) bool {
142143 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
144145 }
145146 return false
146147}
0 commit comments