@@ -19,6 +19,29 @@ const (
19
19
ReasonPushNotificationsDisabled = "push notifications are disabled"
20
20
)
21
21
22
+ // ProcessorType represents the type of processor involved in the error
23
+ // defined as a custom type for better readability and easier maintenance
24
+ type ProcessorType string
25
+
26
+ const (
27
+ // ProcessorTypes
28
+ ProcessorTypeProcessor = ProcessorType ("processor" )
29
+ ProcessorTypeVoidProcessor = ProcessorType ("void_processor" )
30
+ ProcessorTypeCustom = ProcessorType ("custom" )
31
+ )
32
+
33
+ // ProcessorOperation represents the operation being performed by the processor
34
+ // defined as a custom type for better readability and easier maintenance
35
+ type ProcessorOperation string
36
+
37
+ const (
38
+ // ProcessorOperations
39
+ ProcessorOperationProcess = ProcessorOperation ("process" )
40
+ ProcessorOperationRegister = ProcessorOperation ("register" )
41
+ ProcessorOperationUnregister = ProcessorOperation ("unregister" )
42
+ ProcessorOperationUnknown = ProcessorOperation ("unknown" )
43
+ )
44
+
22
45
// Common error variables for reuse
23
46
var (
24
47
// ErrHandlerNil is returned when attempting to register a nil handler
@@ -29,31 +52,31 @@ var (
29
52
30
53
// ErrHandlerExists creates an error for when attempting to overwrite an existing handler
31
54
func ErrHandlerExists (pushNotificationName string ) error {
32
- return NewHandlerError ("register" , pushNotificationName , ReasonHandlerExists , nil )
55
+ return NewHandlerError (ProcessorOperationRegister , pushNotificationName , ReasonHandlerExists , nil )
33
56
}
34
57
35
58
// ErrProtectedHandler creates an error for when attempting to unregister a protected handler
36
59
func ErrProtectedHandler (pushNotificationName string ) error {
37
- return NewHandlerError ("unregister" , pushNotificationName , ReasonHandlerProtected , nil )
60
+ return NewHandlerError (ProcessorOperationUnregister , pushNotificationName , ReasonHandlerProtected , nil )
38
61
}
39
62
40
63
// VoidProcessor errors
41
64
42
65
// ErrVoidProcessorRegister creates an error for when attempting to register a handler on void processor
43
66
func ErrVoidProcessorRegister (pushNotificationName string ) error {
44
- return NewProcessorError ("void_processor" , "register" , pushNotificationName , ReasonPushNotificationsDisabled , nil )
67
+ return NewProcessorError (ProcessorTypeVoidProcessor , ProcessorOperationRegister , pushNotificationName , ReasonPushNotificationsDisabled , nil )
45
68
}
46
69
47
70
// ErrVoidProcessorUnregister creates an error for when attempting to unregister a handler on void processor
48
71
func ErrVoidProcessorUnregister (pushNotificationName string ) error {
49
- return NewProcessorError ("void_processor" , "unregister" , pushNotificationName , ReasonPushNotificationsDisabled , nil )
72
+ return NewProcessorError (ProcessorTypeVoidProcessor , ProcessorOperationUnregister , pushNotificationName , ReasonPushNotificationsDisabled , nil )
50
73
}
51
74
52
75
// Error type definitions for advanced error handling
53
76
54
77
// HandlerError represents errors related to handler operations
55
78
type HandlerError struct {
56
- Operation string // "register", "unregister", "get"
79
+ Operation ProcessorOperation
57
80
PushNotificationName string
58
81
Reason string
59
82
Err error
@@ -71,7 +94,7 @@ func (e *HandlerError) Unwrap() error {
71
94
}
72
95
73
96
// NewHandlerError creates a new HandlerError
74
- func NewHandlerError (operation , pushNotificationName , reason string , err error ) * HandlerError {
97
+ func NewHandlerError (operation ProcessorOperation , pushNotificationName , reason string , err error ) * HandlerError {
75
98
return & HandlerError {
76
99
Operation : operation ,
77
100
PushNotificationName : pushNotificationName ,
@@ -82,9 +105,9 @@ func NewHandlerError(operation, pushNotificationName, reason string, err error)
82
105
83
106
// ProcessorError represents errors related to processor operations
84
107
type ProcessorError struct {
85
- ProcessorType string // "processor", "void_processor"
86
- Operation string // "process", "register", "unregister"
87
- PushNotificationName string // Name of the push notification involved
108
+ ProcessorType ProcessorType // "processor", "void_processor"
109
+ Operation ProcessorOperation // "process", "register", "unregister"
110
+ PushNotificationName string // Name of the push notification involved
88
111
Reason string
89
112
Err error
90
113
}
@@ -105,7 +128,7 @@ func (e *ProcessorError) Unwrap() error {
105
128
}
106
129
107
130
// NewProcessorError creates a new ProcessorError
108
- func NewProcessorError (processorType , operation , pushNotificationName , reason string , err error ) * ProcessorError {
131
+ func NewProcessorError (processorType ProcessorType , operation ProcessorOperation , pushNotificationName , reason string , err error ) * ProcessorError {
109
132
return & ProcessorError {
110
133
ProcessorType : processorType ,
111
134
Operation : operation ,
@@ -125,23 +148,23 @@ func IsHandlerNilError(err error) bool {
125
148
// IsHandlerExistsError checks if an error is due to attempting to overwrite an existing handler
126
149
func IsHandlerExistsError (err error ) bool {
127
150
if handlerErr , ok := err .(* HandlerError ); ok {
128
- return handlerErr .Operation == "register" && handlerErr .Reason == ReasonHandlerExists
151
+ return handlerErr .Operation == ProcessorOperationRegister && handlerErr .Reason == ReasonHandlerExists
129
152
}
130
153
return false
131
154
}
132
155
133
156
// IsProtectedHandlerError checks if an error is due to attempting to unregister a protected handler
134
157
func IsProtectedHandlerError (err error ) bool {
135
158
if handlerErr , ok := err .(* HandlerError ); ok {
136
- return handlerErr .Operation == "unregister" && handlerErr .Reason == ReasonHandlerProtected
159
+ return handlerErr .Operation == ProcessorOperationUnregister && handlerErr .Reason == ReasonHandlerProtected
137
160
}
138
161
return false
139
162
}
140
163
141
164
// IsVoidProcessorError checks if an error is due to void processor operations
142
165
func IsVoidProcessorError (err error ) bool {
143
166
if procErr , ok := err .(* ProcessorError ); ok {
144
- return procErr .ProcessorType == "void_processor" && procErr .Reason == ReasonPushNotificationsDisabled
167
+ return procErr .ProcessorType == ProcessorTypeVoidProcessor && procErr .Reason == ReasonPushNotificationsDisabled
145
168
}
146
169
return false
147
170
}
0 commit comments