-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patherror.go
More file actions
38 lines (30 loc) · 675 Bytes
/
error.go
File metadata and controls
38 lines (30 loc) · 675 Bytes
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
package gokick
import "fmt"
type Error struct {
code int
message string
description string
}
func NewError(code int, message string) Error {
return Error{code: code, message: message}
}
func (e Error) WithDescription(description string) Error {
e.description = description
return e
}
func (e Error) Code() int {
return e.code
}
func (e Error) Message() string {
return e.message
}
func (e Error) Description() string {
return e.description
}
func (e Error) Error() string {
if e.description == "" {
return fmt.Sprintf("Error %d: %s", e.code, e.message)
} else {
return fmt.Sprintf("Error %d: %s (%s)", e.code, e.message, e.description)
}
}