Skip to content

Commit 398cb6f

Browse files
Update content/exception-filters.md
1 parent acf2dde commit 398cb6f

File tree

1 file changed

+0
-49
lines changed

1 file changed

+0
-49
lines changed

content/exception-filters.md

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -183,55 +183,6 @@ export class HttpExceptionFilter {
183183
> info **Hint** All exception filters should implement the generic `ExceptionFilter<T>` interface. This requires you to provide the `catch(exception: T, host: ArgumentsHost)` method with its indicated signature. `T` indicates the type of the exception.
184184
185185
> warning **Warning** If you are using `@nestjs/platform-fastify` you can use `response.send()` instead of `response.json()`. Don't forget to import the correct types from `fastify`.
186-
187-
like this:
188-
189-
```typescript
190-
@@filename(http-exception.filter)
191-
import { ExceptionFilter, Catch, ArgumentsHost, HttpException } from '@nestjs/common';
192-
import { FastifyReply as Response, FastifyRequest as Request } from 'fastify';
193-
194-
@Catch(HttpException)
195-
export class HttpExceptionFilter implements ExceptionFilter {
196-
catch(exception: HttpException, host: ArgumentsHost) {
197-
const ctx = host.switchToHttp();
198-
const response = ctx.getResponse<Response>();
199-
const request = ctx.getRequest<Request>();
200-
const status = exception.getStatus();
201-
202-
response
203-
.status(status)
204-
.send({
205-
statusCode: status,
206-
timestamp: new Date().toISOString(),
207-
path: request.url,
208-
});
209-
}
210-
}
211-
@@switch
212-
import { Catch, HttpException } from '@nestjs/common';
213-
214-
@Catch(HttpException)
215-
export class HttpExceptionFilter {
216-
catch(exception, host) {
217-
const ctx = host.switchToHttp();
218-
const response = ctx.getResponse();
219-
const request = ctx.getRequest();
220-
const status = exception.getStatus();
221-
222-
response
223-
.status(status)
224-
.send({
225-
statusCode: status,
226-
timestamp: new Date().toISOString(),
227-
path: request.url,
228-
});
229-
}
230-
}
231-
```
232-
233-
> info **Hint** you must install `fastify`
234-
235186
The `@Catch(HttpException)` decorator binds the required metadata to the exception filter, telling Nest that this particular filter is looking for exceptions of type `HttpException` and nothing else. The `@Catch()` decorator may take a single parameter, or a comma-separated list. This lets you set up the filter for several types of exceptions at once.
236187

237188
#### Arguments host

0 commit comments

Comments
 (0)