forked from DanielHeckrath/pushd-client-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.go
More file actions
39 lines (30 loc) · 653 Bytes
/
error.go
File metadata and controls
39 lines (30 loc) · 653 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
39
package client
import (
"fmt"
)
const (
UNEXPECTED_ERROR_MESSAGE = "Unexpected response from stats service: status=%d, body=%s"
INVALID_PARAMETER_ERROR = 40001
ACCOUNT_NOT_EXISTS_ERROR = 40002
ACCOUNT_ALREADY_EXISTS_ERROR = 40003
)
type ClientError struct {
Body string
Code int
}
func (this *ClientError) Error() string {
return this.Body
}
func IsError(err error, code int) bool {
switch e := err.(type) {
case *ClientError:
return e.Code == code
}
return false
}
func newUnexpectedResponseError(code int, body string) error {
return &ClientError{
Body: fmt.Sprintf(UNEXPECTED_ERROR, code, body),
Code: code,
}
}