Created
March 27, 2025 18:51
-
-
Save Vatsalya-singhi/d0a7c8c4109832e24357262f36cd4e9e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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