/
error.go
executable file
·64 lines (51 loc) · 1.23 KB
/
error.go
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
package errors
import "fmt"
type Error interface {
Error() string
Code() string
Number() int
Message() string
InnerCause() string
StackTrace() string
}
type errorImpl struct {
definition ErrorDef
innerCause string
params []interface{}
stackFrame string
}
func (err *errorImpl) Error() string {
innerCause := err.InnerCause()
//params := err.Params()
stackTrace := err.StackTrace()
errorMessage := fmt.Sprintf("%s", err.Message())
//errorMessage := fmt.Sprintf("%s - %s", err.Code(), err.Message())
if innerCause != "" {
errorMessage += fmt.Sprintf(" - %s", innerCause)
}
//if params != "" {
// errorMessage += fmt.Sprintf(" - %s", params)
//}
if stackTrace != "" {
errorMessage += fmt.Sprintf(" - %s", stackTrace)
}
return errorMessage
}
func (err *errorImpl) Code() string {
return err.definition.Code()
}
func (err *errorImpl) Number() int {
return err.definition.number
}
func (err *errorImpl) Message() string {
return fmt.Sprintf(err.definition.Template(), err.params...)
}
func (err *errorImpl) InnerCause() string {
return err.innerCause
}
func (err *errorImpl) StackTrace() string {
return fmt.Sprintf(err.stackFrame)
}
func (err *errorImpl) Params() string {
return fmt.Sprintf("%v", err.params)
}