Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Vatsalya-singhi/d0a7c8c4109832e24357262f36cd4e9e to your computer and use it in GitHub Desktop.
Save Vatsalya-singhi/d0a7c8c4109832e24357262f36cd4e9e to your computer and use it in GitHub Desktop.
import { Injectable, NestInterceptor, ExecutionContext, CallHandler, HttpException, HttpStatus } from '@nestjs/common';
import { Observable } from 'rxjs';
import { catchError } from 'rxjs/operators';
@Injectable()
export class ErrorHandlingInterceptor implements NestInterceptor {
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
return next.handle().pipe(
catchError(err => {
throw new HttpException('Something went wrong', HttpStatus.INTERNAL_SERVER_ERROR);
})
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment