Skip to content

Commit 37fc01a

Browse files
committed
feat: added JSONValidationErrorResponse struct
1 parent 1ae5865 commit 37fc01a

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

http/handler/constants.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package handler
2+
3+
var (
4+
// Handler messages
5+
FailedValidations = "failed validations"
6+
)

http/handler/handler.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ func (d *DefaultHandler) HandleValidations(
107107
d.HandleResponse(
108108
w,
109109
gonethttpresponse.NewResponseWithCode(
110-
validations,
110+
gonethttpresponse.NewJSONValidationErrorResponse(
111+
validations,
112+
FailedValidations,
113+
),
111114
http.StatusBadRequest,
112115
),
113116
)

http/response/types.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ type (
1212
JSONErrorResponse struct {
1313
Error string `json:"error"`
1414
}
15+
16+
// JSONValidationErrorResponse struct
17+
JSONValidationErrorResponse struct {
18+
Message string `json:"message"`
19+
Error interface{} `json:"error"`
20+
}
1521
)
1622

1723
// NewJSONErrorResponse creates a new error response
@@ -24,6 +30,14 @@ func NewJSONErrorResponseFromString(err string) *JSONErrorResponse {
2430
return &JSONErrorResponse{Error: err}
2531
}
2632

33+
// NewJSONValidationErrorResponse creates a new validation error response
34+
func NewJSONValidationErrorResponse(
35+
err interface{},
36+
message string,
37+
) *JSONValidationErrorResponse {
38+
return &JSONValidationErrorResponse{Error: err, Message: message}
39+
}
40+
2741
// newResponse creates a new response
2842
func newResponse(
2943
data interface{},

0 commit comments

Comments
 (0)