From 758a3aee7052b376bc86e8122c45979e9fe58954 Mon Sep 17 00:00:00 2001 From: Fabio Bonelli Date: Thu, 7 Mar 2024 16:10:28 +0100 Subject: [PATCH] refactor: use fiber constant for error message (#168) --- internal/handlers/logs.go | 8 ++++++-- internal/handlers/publishers.go | 8 ++++++-- internal/handlers/software.go | 2 +- internal/handlers/webhooks.go | 6 +++++- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/internal/handlers/logs.go b/internal/handlers/logs.go index c5af3c7..181e6b0 100644 --- a/internal/handlers/logs.go +++ b/internal/handlers/logs.go @@ -76,7 +76,11 @@ func (p *Log) GetLog(ctx *fiber.Ctx) error { return common.Error(fiber.StatusNotFound, "can't get Log", "Log was not found") } - return common.Error(fiber.StatusInternalServerError, "can't get Log", "internal server error") + return common.Error( + fiber.StatusInternalServerError, + "can't get Log", + fiber.ErrInternalServerError.Message, + ) } return ctx.JSON(&log) @@ -118,7 +122,7 @@ func (p *Log) PatchLog(ctx *fiber.Ctx) error { return common.Error(fiber.StatusNotFound, errMsg, "Log was not found") } - return common.Error(fiber.StatusInternalServerError, errMsg, "internal server error") + return common.Error(fiber.StatusInternalServerError, errMsg, fiber.ErrInternalServerError.Message) } log.Message = logReq.Message diff --git a/internal/handlers/publishers.go b/internal/handlers/publishers.go index f47bd8b..5ad2e44 100644 --- a/internal/handlers/publishers.go +++ b/internal/handlers/publishers.go @@ -88,7 +88,11 @@ func (p *Publisher) GetPublisher(ctx *fiber.Ctx) error { return common.Error(fiber.StatusNotFound, "can't get Publisher", "Publisher was not found") } - return common.Error(fiber.StatusInternalServerError, "can't get Publisher", "internal server error") + return common.Error( + fiber.StatusInternalServerError, + "can't get Publisher", + fiber.ErrInternalServerError.Message, + ) } return ctx.JSON(&publisher) @@ -155,7 +159,7 @@ func (p *Publisher) PostPublisher(ctx *fiber.Ctx) error { default: return common.Error(fiber.StatusInternalServerError, "can't create Publisher", - "internal server error") + fiber.ErrInternalServerError.Message) } } diff --git a/internal/handlers/software.go b/internal/handlers/software.go index cb83a92..b71dc31 100644 --- a/internal/handlers/software.go +++ b/internal/handlers/software.go @@ -182,7 +182,7 @@ func (p *Software) PatchSoftware(ctx *fiber.Ctx) error { //nolint:funlen,cyclop return common.Error(fiber.StatusNotFound, errMsg, "Software was not found") } - return common.Error(fiber.StatusInternalServerError, errMsg, err.Error()) + return common.Error(fiber.StatusInternalServerError, errMsg, fiber.ErrInternalServerError.Message) } if err := common.ValidateRequestEntity(ctx, &softwareReq, errMsg); err != nil { diff --git a/internal/handlers/webhooks.go b/internal/handlers/webhooks.go index 0378bab..f88d325 100644 --- a/internal/handlers/webhooks.go +++ b/internal/handlers/webhooks.go @@ -28,7 +28,11 @@ func (p *Webhook[T]) GetWebhook(ctx *fiber.Ctx) error { return common.Error(fiber.StatusNotFound, "can't get Webhook", "Webhook was not found") } - return common.Error(fiber.StatusInternalServerError, "can't get Webhook", "internal server error") + return common.Error( + fiber.StatusInternalServerError, + "can't get Webhook", + fiber.ErrInternalServerError.Message, + ) } return ctx.JSON(&webhook)