Skip to content

Commit

Permalink
fix(server): closed connections (immich-app#10013)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasm91 authored Jun 6, 2024
1 parent ca12f3b commit 4ad97cc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
14 changes: 6 additions & 8 deletions server/src/middleware/error.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@nestjs/common';
import { Observable, catchError, throwError } from 'rxjs';
import { ILoggerRepository } from 'src/interfaces/logger.interface';
import { isConnectionAborted, routeToErrorMessage } from 'src/utils/misc';
import { routeToErrorMessage } from 'src/utils/misc';

@Injectable()
export class ErrorInterceptor implements NestInterceptor {
Expand All @@ -21,15 +21,13 @@ export class ErrorInterceptor implements NestInterceptor {
return next.handle().pipe(
catchError((error) =>
throwError(() => {
if (error instanceof HttpException === false) {
const errorMessage = routeToErrorMessage(context.getHandler().name);
if (!isConnectionAborted(error)) {
this.logger.error(errorMessage, error, error?.errors, error?.stack);
}
return new InternalServerErrorException(errorMessage);
} else {
if (error instanceof HttpException) {
return error;
}

const errorMessage = routeToErrorMessage(context.getHandler().name);
this.logger.error(errorMessage, error, error?.errors, error?.stack);
return new InternalServerErrorException(errorMessage);
}),
),
);
Expand Down
10 changes: 6 additions & 4 deletions server/src/middleware/http-exception.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ export class HttpExceptionFilter implements ExceptionFilter {
};
}

response.status(status).json({
...responseBody,
correlationId: this.cls.getId(),
});
if (!response.headersSent) {
response.status(status).json({
...responseBody,
correlationId: this.cls.getId(),
});
}
}
}
2 changes: 1 addition & 1 deletion server/src/utils/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const sendFile = async (

await access(file.path, constants.R_OK);

return _sendFile(file.path, options);
return await _sendFile(file.path, options);
} catch (error: Error | any) {
// ignore client-closed connection
if (isConnectionAborted(error)) {
Expand Down

0 comments on commit 4ad97cc

Please sign in to comment.