-
Notifications
You must be signed in to change notification settings - Fork 0
/
general.error.go
74 lines (60 loc) · 1.67 KB
/
general.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package errmsgs
import (
"fmt"
"net/http"
"strings"
core "github.com/Leakageonthelamp/go-leakage-core"
)
func IsNotFoundError(err core.IError) bool {
if err == nil {
return false
}
return err.GetStatus() == http.StatusNotFound
}
func IsNotFoundErrorCode(code string) bool {
return code == NotFound.Code
}
var (
DBError = core.Error{
Status: http.StatusInternalServerError,
Code: "DATABASE_ERROR",
Message: "database internal error"}
MQError = core.Error{
Status: http.StatusInternalServerError,
Code: "MQ_ERROR",
Message: "mq internal error"}
CacheError = core.Error{
Status: http.StatusInternalServerError,
Code: "CACHE_ERROR",
Message: "cache internal error"}
CronjobError = core.Error{
Status: http.StatusInternalServerError,
Code: "CRONJOB_ERROR",
Message: "cronjob internal error"}
InternalServerError = core.Error{
Status: http.StatusInternalServerError,
Code: "INTERNAL_SERVER_ERROR",
Message: "Internal server error"}
NotFound = core.Error{
Status: http.StatusNotFound,
Code: "NOT_FOUND",
Message: "not found"}
BadRequest = core.Error{
Status: http.StatusBadRequest,
Code: "BAD_REQUEST",
Message: "bad request"}
SignatureInValid = core.Error{
Status: http.StatusBadRequest,
Code: "INVALID_SIGNATURE",
Message: "Signature is not valid"}
JSONInValid = core.Error{
Status: http.StatusBadRequest,
Code: "INVALID_JSON",
Message: "Must be json format"}
)
func NotFoundCustomError(key string) core.Error {
return core.Error{
Status: http.StatusNotFound,
Code: fmt.Sprintf("%s_NOT_FOUND", strings.ToUpper(key)),
Message: fmt.Sprintf("%s is not found", strings.ToLower(key))}
}