Skip to content

Commit

Permalink
Use interceptor instead of genericErrorFilter.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Sonmezturk committed Jul 11, 2023
1 parent 1d25022 commit ea90272
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 40 deletions.
2 changes: 0 additions & 2 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Body, Controller, Get, Post, Query, UseFilters } from '@nestjs/common';
import { AppService } from './app.service';
import { GenericErrorFilter } from './genericErrorFilter';
import {
GetPoolAndTokenVolumesReply,
GetPoolAndTokenVolumesRequest,
Expand All @@ -10,7 +9,6 @@ import {
} from './interfaces/IController';

@Controller()
@UseFilters(new GenericErrorFilter())
export class AppController {
constructor(private readonly appService: AppService) {}

Expand Down
32 changes: 23 additions & 9 deletions src/generic.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Injectable,
NestInterceptor,
} from '@nestjs/common';
import { Observable } from 'rxjs';
import { Observable, tap } from 'rxjs';
import { log } from './util/logger/logger';

@Injectable()
Expand All @@ -15,13 +15,27 @@ export class GenericInterceptor implements NestInterceptor {
): Observable<any> {
const req = context.switchToHttp().getRequest();
const endpoint = context.getHandler();
log.info({
message:
endpoint.name == 'getPoolAndTokenVolumes'
? ''
: JSON.stringify(req.query),
endpoint: endpoint.name,
});
return next.handle().pipe();

return next.handle().pipe(
tap({
next: (value) => {
log.info({
message:
endpoint.name == 'getPoolAndTokenVolumes'
? ''
: JSON.stringify(req.query),
endpoint: endpoint.name,
});
},
error: (err: Error) => {
log.error({
message: err?.message,
stack: err?.stack || '',
detail: err?.name,
endpoint: endpoint.name,
});
},
}),
);
}
}
29 changes: 0 additions & 29 deletions src/genericErrorFilter.ts

This file was deleted.

0 comments on commit ea90272

Please sign in to comment.