25 lines
775 B
TypeScript
25 lines
775 B
TypeScript
import { ArgumentsHost, Catch, Logger } from '@nestjs/common';
|
|
import { BaseRpcExceptionFilter } from '@nestjs/microservices';
|
|
import { Observable } from 'rxjs';
|
|
|
|
@Catch()
|
|
export class LogCauseExceptionFilter extends BaseRpcExceptionFilter {
|
|
private static readonly causeLogger = new Logger('RpcExceptionsHandler');
|
|
|
|
catch(exception: any, host: ArgumentsHost): Observable<any> {
|
|
const response = super.catch(exception, host);
|
|
const cause = exception.cause;
|
|
if (cause) {
|
|
if (this.isError(cause)) {
|
|
LogCauseExceptionFilter.causeLogger.error(
|
|
'Caused by: ' + cause.message,
|
|
cause.stack,
|
|
);
|
|
} else {
|
|
LogCauseExceptionFilter.causeLogger.error('Caused by: ' + cause);
|
|
}
|
|
}
|
|
return response;
|
|
}
|
|
}
|