From 5843da2d026ef56d0afa4d4f7cf72b19d22d05b2 Mon Sep 17 00:00:00 2001 From: GitBluub Date: Tue, 30 May 2023 02:07:36 +0900 Subject: [PATCH] fix: back crash if file not found --- back/src/artist/artist.controller.ts | 4 +++- back/src/genre/genre.controller.ts | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/back/src/artist/artist.controller.ts b/back/src/artist/artist.controller.ts index 56b4606..8077a9a 100644 --- a/back/src/artist/artist.controller.ts +++ b/back/src/artist/artist.controller.ts @@ -21,7 +21,7 @@ import { Request } from 'express'; import { ArtistService } from './artist.service'; import { Prisma, Artist } from '@prisma/client'; import { ApiTags } from '@nestjs/swagger'; -import { createReadStream } from 'fs'; +import { createReadStream, existsSync } from 'fs'; @Controller('artist') @ApiTags('artist') @@ -47,6 +47,8 @@ export class ArtistController { const artist = await this.service.get({ id }); if (!artist) throw new NotFoundException('Artist not found'); const path = `/assets/artists/${artist.name}/illustration.png`; + if (!existsSync(path)) + throw new NotFoundException('Illustration not found'); try { const file = createReadStream(path); diff --git a/back/src/genre/genre.controller.ts b/back/src/genre/genre.controller.ts index b349a44..c2d8288 100644 --- a/back/src/genre/genre.controller.ts +++ b/back/src/genre/genre.controller.ts @@ -21,7 +21,7 @@ import { Request } from 'express'; import { GenreService } from './genre.service'; import { Prisma, Genre } from '@prisma/client'; import { ApiTags } from '@nestjs/swagger'; -import { createReadStream } from 'fs'; +import { createReadStream, existsSync } from 'fs'; @Controller('genre') @ApiTags('genre') @@ -47,6 +47,8 @@ export class GenreController { const genre = await this.service.get({ id }); if (!genre) throw new NotFoundException('Genre not found'); const path = `/assets/genres/${genre.name}/illustration.png`; + if (!existsSync(path)) + throw new NotFoundException('Illustration not found'); try { const file = createReadStream(path);