@@ -3,7 +3,6 @@ package push
3
3
import (
4
4
"errors"
5
5
"fmt"
6
- "strings"
7
6
)
8
7
9
8
// Push notification error definitions
@@ -19,24 +18,24 @@ var (
19
18
20
19
// ErrHandlerExists creates an error for when attempting to overwrite an existing handler
21
20
func 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 )
23
22
}
24
23
25
24
// ErrProtectedHandler creates an error for when attempting to unregister a protected handler
26
25
func 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 )
28
27
}
29
28
30
29
// VoidProcessor errors
31
30
32
31
// ErrVoidProcessorRegister creates an error for when attempting to register a handler on void processor
33
32
func 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 )
35
34
}
36
35
37
36
// ErrVoidProcessorUnregister creates an error for when attempting to unregister a handler on void processor
38
37
func 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 )
40
39
}
41
40
42
41
// Error message constants for consistency
@@ -118,33 +117,37 @@ func IsHandlerNilError(err error) bool {
118
117
119
118
// IsHandlerExistsError checks if an error is due to attempting to overwrite an existing handler
120
119
func 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"
123
122
}
124
- return fmt . Sprintf ( "%v" , err ) == fmt . Sprintf ( MsgHandlerExists , extractNotificationName ( err ))
123
+ return false
125
124
}
126
125
127
126
// IsProtectedHandlerError checks if an error is due to attempting to unregister a protected handler
128
127
func 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"
131
130
}
132
- return fmt . Sprintf ( "%v" , err ) == fmt . Sprintf ( MsgProtectedHandler , extractNotificationName ( err ))
131
+ return false
133
132
}
134
133
135
134
// IsVoidProcessorError checks if an error is due to void processor operations
136
135
func 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"
139
138
}
140
- errStr := err .Error ()
141
- return strings .Contains (errStr , "push notifications are disabled (using void processor)" )
139
+ return false
142
140
}
143
141
144
142
// extractNotificationName attempts to extract the notification name from error messages
145
- // This is a helper function for error type checking
146
143
func 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
+ }
149
152
return "unknown"
150
153
}
0 commit comments