generated from VLADIMIR/template
44 lines
2.0 KiB
Go
44 lines
2.0 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"log"
|
|
|
|
"evening_detective_server/internal/services/device_presence_service"
|
|
"evening_detective_server/internal/services/game_service"
|
|
"evening_detective_server/internal/services/screen_service"
|
|
"evening_detective_server/internal/services/team_service"
|
|
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
func deviceErrorStatus(err error) error {
|
|
switch {
|
|
case errors.Is(err, context.Canceled):
|
|
return status.Error(codes.Canceled, "запрос отменён")
|
|
case errors.Is(err, context.DeadlineExceeded):
|
|
return status.Error(codes.DeadlineExceeded, "время запроса истекло")
|
|
case errors.Is(err, device_presence_service.ErrInvalid):
|
|
return status.Error(codes.InvalidArgument, device_presence_service.ErrInvalid.Error())
|
|
case errors.Is(err, device_presence_service.ErrDisabled):
|
|
return status.Error(codes.FailedPrecondition, device_presence_service.ErrDisabled.Error())
|
|
case errors.Is(err, device_presence_service.ErrPermission):
|
|
return status.Error(codes.PermissionDenied, device_presence_service.ErrPermission.Error())
|
|
case errors.Is(err, device_presence_service.ErrUnauthorized):
|
|
return status.Error(codes.Unauthenticated, device_presence_service.ErrUnauthorized.Error())
|
|
case errors.Is(err, device_presence_service.ErrFull):
|
|
return status.Error(codes.ResourceExhausted, device_presence_service.ErrFull.Error())
|
|
case errors.Is(err, team_service.ErrTeamNotFound):
|
|
return status.Error(codes.NotFound, team_service.ErrTeamNotFound.Error())
|
|
case errors.Is(err, game_service.ErrGameNotFound):
|
|
return status.Error(codes.NotFound, game_service.ErrGameNotFound.Error())
|
|
case errors.Is(err, screen_service.ErrScreenNotFound):
|
|
return status.Error(codes.Unauthenticated, "недействительная сессия экрана")
|
|
default:
|
|
log.Printf("device presence: %v", err)
|
|
return status.Error(codes.Internal, "не удалось обновить учёт устройств")
|
|
}
|
|
}
|