@@ -16,6 +16,13 @@ var DefaultErrorDetail = "Request failed, something went wrong."
16
16
// DefaultTitle can be customized to provide a more customized ISE Title
17
17
var DefaultErrorTitle = "Internal Server Error"
18
18
19
+ // ErrorType represents the common interface requirements that libraries may
20
+ // specify if they would like to accept either a single error or a list
21
+ type ErrorType interface {
22
+ Error () string
23
+ Validate (r * http.Request , response bool ) * Error
24
+ }
25
+
19
26
// ErrorList is wraps an Error Array so that it can implement Sendable
20
27
type ErrorList []* Error
21
28
@@ -31,6 +38,17 @@ func (e ErrorList) Validate(r *http.Request, response bool) *Error {
31
38
return nil
32
39
}
33
40
41
+ // Fulfills the default error interface
42
+ func (e ErrorList ) Error () string {
43
+ var msg string
44
+
45
+ for _ , err := range e {
46
+ msg += fmt .Sprintf ("%s\n " , err .Error ())
47
+ }
48
+
49
+ return msg
50
+ }
51
+
34
52
/*
35
53
Error consists of a number of contextual attributes to make conveying
36
54
certain error type simpler as per the JSON API specification:
@@ -60,21 +78,13 @@ format if not. As usual, err.Error() should not be considered safe for presentat
60
78
to the end user, use err.SafeError() instead.
61
79
*/
62
80
func (e * Error ) Error () string {
63
- if e .ISE != "" {
64
- return fmt .Sprintf ("HTTP %d - %s" , e .Status , e .ISE )
81
+ msg := fmt .Sprintf ("%d: %s - %s" , e .Status , e .Title , e .Detail )
82
+ if e .Source .Pointer != "" {
83
+ msg += fmt .Sprintf ("(Source.Pointer: %s)" , e .Source .Pointer )
65
84
}
66
85
67
- return e .SafeError ()
68
- }
69
-
70
- /*
71
- SafeError is a formatted error string that does not include an associated internal
72
- server error such that it is safe to return this error message to an end user.
73
- */
74
- func (e * Error ) SafeError () string {
75
- msg := fmt .Sprintf ("HTTP %d: %s - %s" , e .Status , e .Title , e .Detail )
76
- if e .Source .Pointer != "" {
77
- msg += fmt .Sprintf ("Source.Pointer: %s" , e .Source .Pointer )
86
+ if e .ISE != "" {
87
+ msg += fmt .Sprintf ("\n Internal Error: %s" , e .ISE )
78
88
}
79
89
80
90
return msg
0 commit comments