Skip to content

Commit cdf559d

Browse files
committed
revert microservice handling
1 parent c197522 commit cdf559d

File tree

5 files changed

+265
-204
lines changed

5 files changed

+265
-204
lines changed

packages/nestjs/rollup.npm.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollu
22

33
export default makeNPMConfigVariants(
44
makeBaseNPMConfig({
5-
entrypoints: ['src/index.ts', 'src/setup.ts', 'src/microservices.ts'],
5+
entrypoints: ['src/index.ts', 'src/setup.ts'],
66
}),
77
);

packages/nestjs/src/microservices.ts

Lines changed: 0 additions & 71 deletions
This file was deleted.

packages/nestjs/src/setup.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,36 @@ class SentryGlobalFilter extends BaseExceptionFilter {
105105
throw exception;
106106
}
107107

108-
// Skip RPC contexts - they should be handled by SentryRpcFilter if the user has included it
108+
// Handle microservice context (rpc)
109+
// We cannot add proper handing here since RpcException depend on the @nestjs/microservices package
110+
// For these cases we log a warning that the user should be providing a dedicated exception filter
109111
if (contextType === 'rpc') {
110-
// Let it propagate to a properly configured RPC filter if present
111-
// Else it will be handled by the default NestJS exception system
112-
throw exception;
112+
// Unlikely case
113+
if (exception instanceof HttpException) {
114+
throw exception;
115+
}
116+
117+
// Handle any other kind of error
118+
if (!(exception instanceof Error)) {
119+
if (!isExpectedError(exception)) {
120+
captureException(exception);
121+
}
122+
throw exception;
123+
}
124+
125+
// In this case we're likely running into an RpcException, which the user should handle with a dedicated filter
126+
// https://github.com/nestjs/nest/blob/master/sample/03-microservices/src/common/filters/rpc-exception.filter.ts
127+
if (!isExpectedError(exception)) {
128+
captureException(exception);
129+
}
130+
131+
this._logger.warn(
132+
'IMPORTANT: RpcException should be handled with a dedicated Rpc exception filter, not the generic SentryGlobalFilter',
133+
);
134+
135+
// Log the error and return, otherwise we may crash the user's app by handling rpc errors in a http context
136+
this._logger.error(exception.message, exception.stack);
137+
return;
113138
}
114139

115140
// HTTP exceptions

packages/nestjs/test/microservices.test.ts

Lines changed: 0 additions & 128 deletions
This file was deleted.

0 commit comments

Comments
 (0)