-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
65 lines (55 loc) · 1.22 KB
/
errors.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
package main
// ErrorAPI - creates
type ErrorAPI struct {
Error ErrorAPIContent `json:"error"`
StatusCode int `json:"status_code"`
}
// ErrorAPIContent - creates
type ErrorAPIContent struct {
Msg []ErrorAPIMessage `json:"messages"`
}
// ErrorAPIMessage - creates
type ErrorAPIMessage struct {
Key string `json:"key"`
Value string `json:"value"`
}
// ErrorAssetAlreadyExists - desc
func ErrorAssetAlreadyExists() ErrorAPI {
a := ErrorAPI{}
a.StatusCode = 409
return a
}
// ErrorForbidden - desc
func ErrorForbidden() ErrorAPI {
a := ErrorAPI{}
a.StatusCode = 403
a.AddMessage("ldap-users", "Forbidden")
return a
}
// ErrorLDAPConn - desc
func ErrorLDAPConn() ErrorAPI {
a := ErrorAPI{}
a.StatusCode = 500
return a
}
// ErrorAssetNotFound - desc
func ErrorAssetNotFound() ErrorAPI {
a := ErrorAPI{}
a.StatusCode = 404
return a
}
// ErrorValidation - desc
func ErrorValidation() ErrorAPI {
a := ErrorAPI{}
a.StatusCode = 400
return a
}
// AddMessage - desc
func (a *ErrorAPI) AddMessage(key string, val string) *ErrorAPI {
a.Error.Msg = append(a.Error.Msg, ErrorAPIMessage{Key: key, Value: val})
return a
}
// GetMessages - desc
func (a *ErrorAPI) GetMessages() []ErrorAPIMessage {
return a.Error.Msg
}