-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherror.go
40 lines (34 loc) · 924 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
package gottbot
import (
"fmt"
)
var (
AttachmentNotReadyError = &Error{
Code: "attachment.not.ready",
Message: "Key: errors.process.attachment.file.not.processed",
}
InvalidPhotoPayloadError = &Error{
Code: "proto.payload",
Message: "No `photos`, `url` or `token` provided. Check payload.",
}
)
// Error Server returns this if there was an exception to your request
type Error struct {
// Code Error code
Code string `json:"code"`
// Message Human-readable description
Message string `json:"message"`
}
func (e *Error) Error() string {
return fmt.Sprintf("An error occured with the code '%s' due to '%s'", e.Code, e.Message)
}
func EqErrors(err error, target *Error) bool {
unwrappedErr, ok := err.(*Error)
if !ok {
return false
}
if target.Message == "" {
return unwrappedErr.Code == target.Code
}
return unwrappedErr.Code == target.Code && unwrappedErr.Message == target.Message
}