File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,11 +9,11 @@ import (
99// handler is the base struct for handling requests
1010type handler struct {}
1111
12- func (h * handler ) responseBadRequest (c * fiber.Ctx , payload any ) error {
12+ func (h * handler ) responseBadRequest (c * fiber.Ctx , err error ) error {
1313 return c .Status (fiber .StatusBadRequest ).JSON (fiber.Map {
1414 "status" : "error" ,
1515 "message" : "The request isn't properly formed" ,
16- "data" : payload ,
16+ "data" : err ,
1717 })
1818}
1919
Original file line number Diff line number Diff line change @@ -43,6 +43,9 @@ func NewMessageHandler(
4343// @Accept json
4444// @Produce json
4545// @Success 200 {object} responses.MessageResponse
46+ // @Success 400 {object} responses.BadRequest
47+ // @Success 422 {object} responses.UnprocessableEntity
48+ // @Success 500 {object} responses.InternalServerError
4649// @Router /messages/send [post]
4750func (h * MessageHandler ) Send (c * fiber.Ctx ) error {
4851 ctx , span := h .tracer .StartFromFiberCtx (c )
Original file line number Diff line number Diff line change @@ -4,3 +4,23 @@ type response struct {
44 Status string `json:"status" example:"success"`
55 Message string `json:"message" example:"item created successfully"`
66}
7+
8+ // InternalServerError is the response with status code is 500
9+ type InternalServerError struct {
10+ Status string `json:"status" example:"error"`
11+ Message string `json:"message" example:"We ran into an internal error while handling the request."`
12+ }
13+
14+ // BadRequest is the response with status code is 400
15+ type BadRequest struct {
16+ Status string `json:"status" example:"error"`
17+ Message string `json:"message" example:"The request isn't properly formed"`
18+ Data string `json:"data" example:"The request body is not a valid JSON string"`
19+ }
20+
21+ // UnprocessableEntity is the response with status code is 422
22+ type UnprocessableEntity struct {
23+ Status string `json:"status" example:"error"`
24+ Message string `json:"message" example:"validation errors while sending message"`
25+ Data map [string ][]string `json:"data"`
26+ }
You can’t perform that action at this time.
0 commit comments