forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
47 lines (38 loc) · 789 Bytes
/
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
package errors
import (
original "errors"
"fmt"
)
type Error interface {
error
ErrorCode() string
}
type concreteError struct {
Message string
errorCode string
}
func New(message string) error {
return original.New(message)
}
func NewError(message string, errorCode string) Error {
return &concreteError{
Message: message,
errorCode: errorCode,
}
}
func NewErrorWithMessage(message string, a ...interface{}) Error {
return &concreteError{
Message: fmt.Sprintf(message, a...),
}
}
func NewErrorWithError(message string, err error) Error {
return &concreteError{
Message: fmt.Sprintf("%s: %s", message, err.Error()),
}
}
func (err *concreteError) Error() string {
return err.Message
}
func (err *concreteError) ErrorCode() string {
return err.errorCode
}