-
Notifications
You must be signed in to change notification settings - Fork 672
/
error.go
43 lines (34 loc) · 852 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
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package common
import "fmt"
var (
_ error = (*AppError)(nil)
// ErrUndefined indicates an undefined error
ErrUndefined = &AppError{
Code: 0,
Message: "undefined",
}
// ErrTimeout is used to signal a response timeout
ErrTimeout = &AppError{
Code: -1,
Message: "timed out",
}
)
// AppError is an application-defined error
type AppError struct {
// Code is application-defined and should be used for error matching
Code int32
// Message is a human-readable error message
Message string
}
func (a *AppError) Error() string {
return fmt.Sprintf("%d: %s", a.Code, a.Message)
}
func (a *AppError) Is(target error) bool {
appErr, ok := target.(*AppError)
if !ok {
return false
}
return a.Code == appErr.Code
}