Skip to content

Commit 23a3688

Browse files
committed
Fix documentation
1 parent a324c2a commit 23a3688

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

api/pkg/handlers/handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import (
99
// handler is the base struct for handling requests
1010
type 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

api/pkg/handlers/message_handler.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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]
4750
func (h *MessageHandler) Send(c *fiber.Ctx) error {
4851
ctx, span := h.tracer.StartFromFiberCtx(c)

api/pkg/responses/response.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
}

0 commit comments

Comments
 (0)