@@ -3,7 +3,6 @@ package push
33import (
44 "errors"
55 "fmt"
6- "strings"
76)
87
98// Push notification error definitions
@@ -19,24 +18,24 @@ var (
1918
2019// ErrHandlerExists creates an error for when attempting to overwrite an existing handler
2120func ErrHandlerExists (pushNotificationName string ) error {
22- return fmt . Errorf ( " cannot overwrite existing handler for push notification: %s " , pushNotificationName )
21+ return NewHandlerError ( "register" , pushNotificationName , " cannot overwrite existing handler" , nil )
2322}
2423
2524// ErrProtectedHandler creates an error for when attempting to unregister a protected handler
2625func ErrProtectedHandler (pushNotificationName string ) error {
27- return fmt . Errorf ( "cannot unregister protected handler for push notification: %s " , pushNotificationName )
26+ return NewHandlerError ( " unregister" , pushNotificationName , " handler is protected " , nil )
2827}
2928
3029// VoidProcessor errors
3130
3231// ErrVoidProcessorRegister creates an error for when attempting to register a handler on void processor
3332func ErrVoidProcessorRegister (pushNotificationName string ) error {
34- return fmt . Errorf ( "cannot register push notification handler '%s': push notifications are disabled (using void processor) " , pushNotificationName )
33+ return NewProcessorError ( "void_processor" , " register" , " push notifications are disabled" , nil )
3534}
3635
3736// ErrVoidProcessorUnregister creates an error for when attempting to unregister a handler on void processor
3837func ErrVoidProcessorUnregister (pushNotificationName string ) error {
39- return fmt . Errorf ( "cannot unregister push notification handler '%s': push notifications are disabled (using void processor) " , pushNotificationName )
38+ return NewProcessorError ( "void_processor" , " unregister" , " push notifications are disabled" , nil )
4039}
4140
4241// Error message constants for consistency
@@ -118,33 +117,37 @@ func IsHandlerNilError(err error) bool {
118117
119118// IsHandlerExistsError checks if an error is due to attempting to overwrite an existing handler
120119func IsHandlerExistsError (err error ) bool {
121- if err == nil {
122- return false
120+ if handlerErr , ok := err .( * HandlerError ); ok {
121+ return handlerErr . Operation == "register" && handlerErr . Reason == "cannot overwrite existing handler"
123122 }
124- return fmt . Sprintf ( "%v" , err ) == fmt . Sprintf ( MsgHandlerExists , extractNotificationName ( err ))
123+ return false
125124}
126125
127126// IsProtectedHandlerError checks if an error is due to attempting to unregister a protected handler
128127func IsProtectedHandlerError (err error ) bool {
129- if err == nil {
130- return false
128+ if handlerErr , ok := err .( * HandlerError ); ok {
129+ return handlerErr . Operation == "unregister" && handlerErr . Reason == "handler is protected"
131130 }
132- return fmt . Sprintf ( "%v" , err ) == fmt . Sprintf ( MsgProtectedHandler , extractNotificationName ( err ))
131+ return false
133132}
134133
135134// IsVoidProcessorError checks if an error is due to void processor operations
136135func IsVoidProcessorError (err error ) bool {
137- if err == nil {
138- return false
136+ if procErr , ok := err .( * ProcessorError ); ok {
137+ return procErr . ProcessorType == "void_processor" && procErr . Reason == "push notifications are disabled"
139138 }
140- errStr := err .Error ()
141- return strings .Contains (errStr , "push notifications are disabled (using void processor)" )
139+ return false
142140}
143141
144142// extractNotificationName attempts to extract the notification name from error messages
145- // This is a helper function for error type checking
146143func extractNotificationName (err error ) string {
147- // This is a simplified implementation - in practice, you might want more sophisticated parsing
148- // For now, we return a placeholder since the exact extraction logic depends on the error format
144+ if handlerErr , ok := err .(* HandlerError ); ok {
145+ return handlerErr .PushNotificationName
146+ }
147+ if procErr , ok := err .(* ProcessorError ); ok {
148+ // For ProcessorError, we don't have direct access to the notification name
149+ // but in a real implementation you could store this in the struct
150+ return "unknown"
151+ }
149152 return "unknown"
150153}
0 commit comments