add error if user not found
This commit is contained in:
parent
24f2998eac
commit
e0caf399c6
@ -1,6 +1,8 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"amocrm/internal/service_errors"
|
||||
"errors"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/core.git/middleware"
|
||||
@ -63,6 +65,9 @@ func (c *Controller) GetCurrentAccount(ctx *fiber.Ctx) error {
|
||||
|
||||
response, err := c.service.GetCurrentAccount(ctx.Context(), accountID)
|
||||
if err != nil {
|
||||
if errors.Is(err, service_errors.ErrUserNotFound) {
|
||||
return ctx.Status(fiber.StatusNotFound).SendString("user not found")
|
||||
}
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,9 @@ package service
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"amocrm/internal/service_errors"
|
||||
"context"
|
||||
"database/sql"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
)
|
||||
@ -43,6 +45,9 @@ func (s *Service) SoftDeleteAccount(ctx context.Context, accountID string) error
|
||||
func (s *Service) GetCurrentAccount(ctx context.Context, accountID string) (*model.User, error) {
|
||||
user, err := s.repository.AmoRepo.GetCurrentAccount(ctx, accountID)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, service_errors.ErrUserNotFound
|
||||
}
|
||||
s.logger.Error("error getting current account in getCurrentAccount service", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
5
internal/service_errors/pg_error.go
Normal file
5
internal/service_errors/pg_error.go
Normal file
@ -0,0 +1,5 @@
|
||||
package service_errors
|
||||
|
||||
import "errors"
|
||||
|
||||
var ErrUserNotFound = errors.New("user not found")
|
Loading…
Reference in New Issue
Block a user