fix: error handling (#28843)

This commit is contained in:
Jason Rasmussen 2026-06-04 16:19:16 -04:00 committed by GitHub
parent b3d49045de
commit 9043bc8435
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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());
}
};