added error handling

This commit is contained in:
Pavel 2024-06-11 19:12:54 +03:00
parent 8196a70912
commit dcac16a2e8
3 changed files with 16 additions and 7 deletions

2
go.mod

@ -18,7 +18,7 @@ require (
google.golang.org/grpc v1.64.0
google.golang.org/protobuf v1.34.1
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240611135631-30262442b2d4
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240611160822-0013810bb882
penahub.gitlab.yandexcloud.net/backend/quiz/worker.git v0.0.0-20240421230341-0e086fcbb990
)

6
go.sum

@ -259,9 +259,7 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6 h1:oV+/HNX+JPoQ3/GUx08hio7d45WpY0AMGrFs7j70QlA=
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6/go.mod h1:lTmpjry+8evVkXWbEC+WMOELcFkRD1lFMc7J09mOndM=
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240610170852-3d0ee4560f62 h1:jCrXJmApWkbdM4o7HKrIBnFpZ8fITsusQVSx1Aefvbk=
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240610170852-3d0ee4560f62/go.mod h1:n66zm88Dh12+idyfqh0vU5nd9BZYxM6Pv0XYnmy0398=
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240611135631-30262442b2d4 h1:1Z1B4G6DA3+izFCK9pstiaoCLFtr1ZHuzeh+JiIRcoY=
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240611135631-30262442b2d4/go.mod h1:n66zm88Dh12+idyfqh0vU5nd9BZYxM6Pv0XYnmy0398=
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240611160822-0013810bb882 h1:Y64tHM2aEO1syR45bV4uiFBSauIrvEzA47XEf6v8Pq8=
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240611160822-0013810bb882/go.mod h1:n66zm88Dh12+idyfqh0vU5nd9BZYxM6Pv0XYnmy0398=
penahub.gitlab.yandexcloud.net/backend/quiz/worker.git v0.0.0-20240421230341-0e086fcbb990 h1:jiO8GWO+3sCnDAV8/NAV8tQIUwae/I6/xiDilW7zf0o=
penahub.gitlab.yandexcloud.net/backend/quiz/worker.git v0.0.0-20240421230341-0e086fcbb990/go.mod h1:zswBuTwmEsFHBVRu1nkG3/Fwylk5Vcm8OUm9iWxccSE=

@ -290,7 +290,13 @@ func (s *Service) GetLeadTarget(ctx *fiber.Ctx) error {
result, err := s.dal.AccountRepo.GetLeadTarget(ctx.Context(), accountID, int32(quizID))
if err != nil {
return ctx.Status(fiber.StatusInternalServerError).SendString(err.Error())
switch {
case errors.Is(err, pj_errors.ErrNotFound):
return ctx.Status(fiber.StatusNotFound).SendString("this lead target not found")
default:
return ctx.Status(fiber.StatusInternalServerError).SendString(err.Error())
}
}
return ctx.Status(fiber.StatusOK).JSON(result)
@ -315,7 +321,12 @@ func (s *Service) UpdateLeadTarget(ctx *fiber.Ctx) error {
Target: req.Target,
})
if err != nil {
return ctx.Status(fiber.StatusInternalServerError).SendString(err.Error())
switch {
case errors.Is(err, pj_errors.ErrNotFound):
return ctx.Status(fiber.StatusNotFound).SendString("this lead target not found")
default:
return ctx.Status(fiber.StatusInternalServerError).SendString(err.Error())
}
}
return ctx.Status(fiber.StatusOK).JSON(result)