-
Notifications
You must be signed in to change notification settings - Fork 0
/
error_response.go
47 lines (40 loc) · 1.12 KB
/
error_response.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
package helpers
import (
"encoding/json"
)
// HTTPStatus returns ErrorResponse.Status
func (error *ErrorResponse) HTTPStatus() int {
return error.Status
}
// Marshal marshals ErrorResponse
func (error *ErrorResponse) Marshal() ([]byte, error) {
return json.MarshalIndent(error, "", " ")
}
// Error returns Message
func (error *ErrorResponse) Error() string {
return error.Message
}
// NewInvalidParameterError creates and returns a new InvalidParameterError
func NewInvalidParameterError(name, moreInfo string) *ErrorResponse {
data := map[string]interface{}{}
if name != "" {
data["name"] = name
}
return &ErrorResponse{
Status: InvalidParameterError.Status,
Code: InvalidParameterError.Code,
Message: InvalidParameterError.Message,
MoreInfo: moreInfo,
Data: data,
}
}
// NewMissingParameter creates and returns a new missingParameterError
func NewMissingParameter(name string) *ErrorResponse {
data := map[string]interface{}{"name": name}
return &ErrorResponse{
Status: missingParameterError.Status,
Code: missingParameterError.Code,
Message: missingParameterError.Message,
Data: data,
}
}