/
error.go
48 lines (38 loc) · 990 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
48
package types
import (
"fmt"
)
// errorCode is the same from services.errorCode.
// We copy the code here to prevent depend cycle.
type errorCode struct {
s string
}
func (e errorCode) Error() string {
return e.s
}
// IsInternalError implements service.InternalError
func (e errorCode) IsInternalError() {}
var (
// ErrNotImplemented will be returned while this operation is not
// implemented by services.
ErrNotImplemented = errorCode{"not implemented"}
)
// OperationError is the error for operation related errors.
type OperationError struct {
op string
err error
}
func (oe OperationError) Error() string {
return fmt.Sprintf("operation %s: %v", oe.op, oe.err)
}
func (oe OperationError) Unwrap() error {
return oe.err
}
func (oe OperationError) IsInternalError() {}
// NewOperationNotImplementedError will create a new NotImplemented error.
func NewOperationNotImplementedError(op string) error {
return OperationError{
op: op,
err: ErrNotImplemented,
}
}