From 9043bc843532bc5c1bb6dca513f599d07de8168f Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Thu, 4 Jun 2026 16:19:16 -0400 Subject: [PATCH] fix: error handling (#28843) --- server/src/utils/file.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/server/src/utils/file.ts b/server/src/utils/file.ts index 04f1ce48d9..edd411dd40 100644 --- a/server/src/utils/file.ts +++ b/server/src/utils/file.ts @@ -1,4 +1,4 @@ -import { HttpException, StreamableFile } from '@nestjs/common'; +import { HttpException, NotFoundException, StreamableFile } from '@nestjs/common'; import { NextFunction, Response } from 'express'; import { access, constants } from 'node:fs/promises'; import { basename, extname } from 'node:path'; @@ -52,6 +52,9 @@ export const sendFile = async ( try { const file = await handler(); + + await access(file.path, constants.R_OK); + const cacheControlHeader = cacheControlHeaders[file.cacheControl]; if (cacheControlHeader) { // set the header to Cache-Control @@ -63,8 +66,6 @@ export const sendFile = async ( res.header('Content-Disposition', `inline; filename*=UTF-8''${encodeURIComponent(file.fileName)}`); } - await access(file.path, constants.R_OK); - return await _sendFile(file.path, { dotfiles: 'allow' }); } catch (error: Error | any) { // ignore client-closed connection @@ -77,8 +78,7 @@ export const sendFile = async ( logger.error(`Unable to send file: ${error}`, error.stack); } - res.header('Cache-Control', 'none'); - next(error); + next(new NotFoundException()); } };