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