-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbad-input.go
More file actions
36 lines (30 loc) · 1.07 KB
/
Copy pathbad-input.go
File metadata and controls
36 lines (30 loc) · 1.07 KB
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
package errors
type BadInputCondition string
const (
BadInputConditionNotValid BadInputCondition = "not_valid"
BadInputConditionNotFound BadInputCondition = "not_found"
)
type BadInputField struct {
Field string `json:"field"`
Condition BadInputCondition `json:"condition"`
Value string `json:"value"`
}
// APIErrorResponse is the documented shape of 400 (bad input / validation) error bodies (OpenAPI).
// Use only for 400 responses so the spec shows message + error array.
type APIErrorResponse struct {
Message string `json:"message" doc:"Error message"`
Error []BadInputField `json:"error,omitempty" doc:"Validation errors (only for 400)"`
}
// APIErrorSimple is the documented shape of 401/403/404/500 error bodies (OpenAPI).
// Message only; no validation error array.
type APIErrorSimple struct {
Message string `json:"message" doc:"Error message"`
}
func NewBadInput(module string, params []BadInputField) *CustomError {
return &CustomError{
Module: module,
Message: "Validation Failed",
Params: params,
Status: 400,
}
}