|
@@ -1,4 +1,4 @@
|
1
|
|
-package errors
|
|
1
|
+package errorHandler
|
2
|
2
|
|
3
|
3
|
const INVALID_PARAMETER = 400
|
4
|
4
|
const ACTION_FORBIDDEN = 401
|
|
@@ -16,49 +16,48 @@ type apiError struct {
|
16
|
16
|
Message string `json:"message"`
|
17
|
17
|
}
|
18
|
18
|
|
19
|
|
-var errors []interface{}
|
|
19
|
+type Errors struct {
|
|
20
|
+ Errors []interface{} `json:"errors"`
|
|
21
|
+}
|
20
|
22
|
|
21
|
|
-func InvalidParameter(parameter string, message string) {
|
|
23
|
+func (err *Errors) InvalidParameter(parameter string, message string) {
|
22
|
24
|
var e = apiErrorParameter{
|
23
|
25
|
"invalid_parameter",
|
24
|
26
|
parameter,
|
25
|
27
|
message,
|
26
|
28
|
}
|
27
|
29
|
|
28
|
|
- errors = append(errors, e)
|
|
30
|
+ err.Errors = append(err.Errors, e)
|
29
|
31
|
}
|
30
|
32
|
|
31
|
|
-func ActionForbidden(message string) {
|
|
33
|
+func (err *Errors) ActionForbidden(message string) {
|
32
|
34
|
var e = apiError{
|
33
|
35
|
"action_forbidden",
|
34
|
36
|
message,
|
35
|
37
|
}
|
36
|
38
|
|
37
|
|
- errors = append(errors, e)
|
|
39
|
+ err.Errors = append(err.Errors, e)
|
38
|
40
|
}
|
39
|
41
|
|
40
|
|
-func InternalError(message string) {
|
|
42
|
+func (err *Errors) InternalError(message string) {
|
41
|
43
|
var e = apiError{
|
42
|
44
|
"internal_error",
|
43
|
45
|
message,
|
44
|
46
|
}
|
45
|
47
|
|
46
|
|
- errors = append(errors, e)
|
|
48
|
+ err.Errors = append(err.Errors, e)
|
|
49
|
+
|
47
|
50
|
}
|
48
|
51
|
|
49
|
|
-func NotFound(message string) {
|
|
52
|
+func (err *Errors) NotFound(message string) {
|
50
|
53
|
var e = apiError{
|
51
|
54
|
"not_found",
|
52
|
55
|
message,
|
53
|
56
|
}
|
54
|
57
|
|
55
|
|
- errors = append(errors, e)
|
56
|
|
-}
|
57
|
|
-
|
58
|
|
-func Has() bool {
|
59
|
|
- return len(errors) > 0
|
|
58
|
+ err.Errors = append(err.Errors, e)
|
60
|
59
|
}
|
61
|
60
|
|
62
|
|
-func Get() []interface{} {
|
63
|
|
- return errors
|
|
61
|
+func (err *Errors) Has() bool {
|
|
62
|
+ return len(err.Errors) > 0
|
64
|
63
|
}
|