-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
71 lines (58 loc) · 1.8 KB
/
Copy patherrors.go
File metadata and controls
71 lines (58 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package gosparkclient
import (
"fmt"
)
// ErrorType represents the type of error that occurred
type ErrorType string
const (
ErrConfiguration ErrorType = "ConfigurationError"
ErrConnection ErrorType = "ConnectionError"
ErrAuthentication ErrorType = "AuthenticationError"
ErrRequest ErrorType = "RequestError"
ErrResponse ErrorType = "ResponseError"
ErrWebSocket ErrorType = "WebSocketError"
)
// SparkError represents a custom error type for the Spark client
type SparkError struct {
Type ErrorType
Message string
Err error
}
// Error implements the error interface
func (e *SparkError) Error() string {
if e.Err != nil {
return fmt.Sprintf("%s: %s (underlying: %v)", e.Type, e.Message, e.Err)
}
return fmt.Sprintf("%s: %s", e.Type, e.Message)
}
// Unwrap returns the underlying error
func (e *SparkError) Unwrap() error {
return e.Err
}
// NewSparkError creates a new SparkError
func NewSparkError(errType ErrorType, message string, err error) *SparkError {
return &SparkError{
Type: errType,
Message: message,
Err: err,
}
}
// Helper functions for creating specific error types
func newConfigError(message string, err error) *SparkError {
return NewSparkError(ErrConfiguration, message, err)
}
func newConnectionError(message string, err error) *SparkError {
return NewSparkError(ErrConnection, message, err)
}
func newAuthError(message string, err error) *SparkError {
return NewSparkError(ErrAuthentication, message, err)
}
func newRequestError(message string, err error) *SparkError {
return NewSparkError(ErrRequest, message, err)
}
func newResponseError(message string, err error) *SparkError {
return NewSparkError(ErrResponse, message, err)
}
func newWebSocketError(message string, err error) *SparkError {
return NewSparkError(ErrWebSocket, message, err)
}