Skip to content

Commit a03db87

Browse files
author
wSedlacek
committed
fix(core): end without message when a response has already sent a header
1 parent fefa752 commit a03db87

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

packages/core/exceptions/base-exception-filter.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ export class BaseExceptionFilter<T = any> implements ExceptionFilter<T> {
3838
message: res,
3939
};
4040

41-
applicationRef.reply(host.getArgByIndex(1), message, exception.getStatus());
41+
const response = host.getArgByIndex(1);
42+
if (!applicationRef.isHeadersSent(response)) {
43+
applicationRef.reply(response, message, exception.getStatus());
44+
} else {
45+
applicationRef.end(response);
46+
}
4247
}
4348

4449
public handleUnknownError(
@@ -55,7 +60,14 @@ export class BaseExceptionFilter<T = any> implements ExceptionFilter<T> {
5560
statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
5661
message: MESSAGES.UNKNOWN_EXCEPTION_MESSAGE,
5762
};
58-
applicationRef.reply(host.getArgByIndex(1), body, body.statusCode);
63+
64+
const response = host.getArgByIndex(1);
65+
if (!applicationRef.isHeadersSent(response)) {
66+
applicationRef.reply(response, body, body.statusCode);
67+
} else {
68+
applicationRef.end(response);
69+
}
70+
5971
if (this.isExceptionObject(exception)) {
6072
return BaseExceptionFilter.logger.error(
6173
exception.message,

0 commit comments

Comments
 (0)