From dcac16a2e8f7cac947bd4c90f506748a38515fc0 Mon Sep 17 00:00:00 2001 From: Pavel Date: Tue, 11 Jun 2024 19:12:54 +0300 Subject: [PATCH] added error handling --- go.mod | 2 +- go.sum | 6 ++---- service/account_svc.go | 15 +++++++++++++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 7f7cc63..e60b975 100644 --- a/go.mod +++ b/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 ) diff --git a/go.sum b/go.sum index 9042bb1..7cc32d5 100644 --- a/go.sum +++ b/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= diff --git a/service/account_svc.go b/service/account_svc.go index 28612e0..cba8266 100644 --- a/service/account_svc.go +++ b/service/account_svc.go @@ -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)