Skip to content

Commit 8418c6b

Browse files
committed
fix(push): fix error checks
1 parent 52f2b2c commit 8418c6b

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

push/errors.go

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ func ErrProtectedHandler(pushNotificationName string) error {
3030

3131
// ErrVoidProcessorRegister creates an error for when attempting to register a handler on void processor
3232
func ErrVoidProcessorRegister(pushNotificationName string) error {
33-
return NewProcessorError("void_processor", "register", "push notifications are disabled", nil)
33+
return NewProcessorError("void_processor", "register", pushNotificationName, "push notifications are disabled", nil)
3434
}
3535

3636
// ErrVoidProcessorUnregister creates an error for when attempting to unregister a handler on void processor
3737
func ErrVoidProcessorUnregister(pushNotificationName string) error {
38-
return NewProcessorError("void_processor", "unregister", "push notifications are disabled", nil)
38+
return NewProcessorError("void_processor", "unregister", pushNotificationName, "push notifications are disabled", nil)
3939
}
4040

4141
// Error message constants for consistency
@@ -81,30 +81,32 @@ func NewHandlerError(operation, pushNotificationName, reason string, err error)
8181

8282
// ProcessorError represents errors related to processor operations
8383
type ProcessorError struct {
84-
ProcessorType string // "processor", "void_processor"
85-
Operation string // "process", "register", "unregister"
86-
Reason string
87-
Err error
84+
ProcessorType string // "processor", "void_processor"
85+
Operation string // "process", "register", "unregister"
86+
PushNotificationName string // Name of the push notification involved
87+
Reason string
88+
Err error
8889
}
8990

9091
func (e *ProcessorError) Error() string {
9192
if e.Err != nil {
92-
return fmt.Sprintf("%s %s failed: %s (%v)", e.ProcessorType, e.Operation, e.Reason, e.Err)
93+
return fmt.Sprintf("%s %s failed for '%s': %s (%v)", e.ProcessorType, e.Operation, e.PushNotificationName, e.Reason, e.Err)
9394
}
94-
return fmt.Sprintf("%s %s failed: %s", e.ProcessorType, e.Operation, e.Reason)
95+
return fmt.Sprintf("%s %s failed for '%s': %s", e.ProcessorType, e.Operation, e.PushNotificationName, e.Reason)
9596
}
9697

9798
func (e *ProcessorError) Unwrap() error {
9899
return e.Err
99100
}
100101

101102
// NewProcessorError creates a new ProcessorError
102-
func NewProcessorError(processorType, operation, reason string, err error) *ProcessorError {
103+
func NewProcessorError(processorType, operation, pushNotificationName, reason string, err error) *ProcessorError {
103104
return &ProcessorError{
104-
ProcessorType: processorType,
105-
Operation: operation,
106-
Reason: reason,
107-
Err: err,
105+
ProcessorType: processorType,
106+
Operation: operation,
107+
PushNotificationName: pushNotificationName,
108+
Reason: reason,
109+
Err: err,
108110
}
109111
}
110112

@@ -142,12 +144,14 @@ func IsVoidProcessorError(err error) bool {
142144
// extractNotificationName attempts to extract the notification name from error messages
143145
func extractNotificationName(err error) string {
144146
if handlerErr, ok := err.(*HandlerError); ok {
145-
return handlerErr.PushNotificationName
147+
if handlerErr.PushNotificationName != "" {
148+
return handlerErr.PushNotificationName
149+
}
146150
}
147151
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"
152+
if procErr.PushNotificationName != "" {
153+
return procErr.PushNotificationName
154+
}
151155
}
152156
return "unknown"
153157
}

0 commit comments

Comments
 (0)