generated from VLADIMIR/template
fix
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"evening_detective_server/internal/modules/file_storage"
|
||||
"evening_detective_server/internal/modules/roles"
|
||||
"evening_detective_server/internal/services/file_service"
|
||||
proto "evening_detective_server/proto"
|
||||
@@ -50,7 +49,7 @@ func (s *server) DownloadFile(ctx context.Context, req *proto.DownloadFileReq) (
|
||||
file, err := s.fileService.DownloadFile(ctx, req.Filename)
|
||||
if err != nil {
|
||||
switch {
|
||||
case errors.Is(err, file_storage.ErrFileNotFound):
|
||||
case errors.Is(err, file_service.ErrFileNotFound):
|
||||
return nil, status.Errorf(codes.NotFound, "%v", err)
|
||||
default:
|
||||
return nil, status.Errorf(codes.Internal, "%v", err)
|
||||
|
||||
@@ -20,6 +20,8 @@ var (
|
||||
ErrInvalidExtension = errors.New("недопустимое расширение файла (разрешены pdf, jpg, jpeg, png, gif, webp, mp3, ogg, wav, mp4, webm)")
|
||||
ErrInvalidContentType = errors.New("содержимое файла не соответствует разрешённым типам (pdf, изображения, аудио или видео)")
|
||||
ErrFileTooLarge = errors.New("файл слишком большой")
|
||||
// ErrFileNotFound — файл отсутствует в хранилище.
|
||||
ErrFileNotFound = errors.New("файл не найден")
|
||||
)
|
||||
|
||||
// allowedExtensions — расширения, разрешённые для загрузки: PDF, изображения
|
||||
@@ -152,6 +154,9 @@ func (s *FileService) DownloadFile(
|
||||
) (*file_storage.File, error) {
|
||||
file, err := s.fileStorage.Get(ctx, filename)
|
||||
if err != nil {
|
||||
if errors.Is(err, file_storage.ErrFileNotFound) {
|
||||
return nil, ErrFileNotFound
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return file, nil
|
||||
|
||||
@@ -155,6 +155,14 @@ func TestUploadFileTooLarge(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDownloadFileNotFound(t *testing.T) {
|
||||
svc := newService(1 << 20)
|
||||
_, err := svc.DownloadFile(context.Background(), "missing.pdf")
|
||||
if !errors.Is(err, ErrFileNotFound) {
|
||||
t.Fatalf("err = %v, want ErrFileNotFound", err)
|
||||
}
|
||||
}
|
||||
|
||||
func bytes1024() []byte {
|
||||
b := make([]byte, 1024)
|
||||
copy(b, "%PDF-1.7 ")
|
||||
|
||||
Reference in New Issue
Block a user