mirror of
https://github.com/immich-app/immich.git
synced 2026-06-04 21:25:49 -04:00
fix: error handling (#28843)
This commit is contained in:
@@ -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());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user