-
Notifications
You must be signed in to change notification settings - Fork 0
/
err_def.go
58 lines (47 loc) · 996 Bytes
/
err_def.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
package errors
import (
"fmt"
"github.com/eadydb/hubble/proto/v1"
)
type Error interface {
Error() string
StatusCode() proto.StatusCode
Suggestions() []*proto.Suggestion
Unwrap() error
}
type ErrDef struct {
err error
ae *proto.ActionableErr
}
var _ error = (*ErrDef)(nil)
func (e *ErrDef) Error() string {
return fmt.Sprintf("xx")
}
func (e *ErrDef) Unwrap() error {
return e.err
}
func (e *ErrDef) StatusCode() proto.StatusCode {
return e.ae.ErrCode
}
func (e *ErrDef) Suggestions() []*proto.Suggestion {
return e.ae.Suggestions
}
// NewError creates an actionable error message preserving the actual error.
func NewError(err error, ae *proto.ActionableErr) *ErrDef {
return &ErrDef{
err: err,
ae: ae,
}
}
// NewErrorWithStatusCode creates an actionable error message.
func NewErrorWithStatusCode(ae *proto.ActionableErr) *ErrDef {
return &ErrDef{
ae: ae,
}
}
func IsHubbleErr(err error) bool {
if _, ok := err.(Error); ok {
return true
}
return false
}