Node.js / NestJS

Error Handling

Exception filters, custom exceptions, HTTP exceptions, error responses, logging

20 mülakat soruları·
Junior
1

What is an exception filter in NestJS?

Cevap

An exception filter is a NestJS component that intercepts exceptions thrown in the application and transforms them into appropriate HTTP responses. It centralizes error handling and avoids code duplication by applying common logic to all exceptions. Filters can be global, applied to a specific controller, or to a particular route depending on the needs.

2

Which NestJS class should be used to return an HTTP 404 error?

Cevap

NotFoundException is the standard NestJS class for returning a 404 (Not Found) error. It inherits from HttpException and automatically configures the appropriate HTTP status code. This exception is ideal when a requested resource does not exist in the database. NestJS provides dedicated classes for each common HTTP error type to simplify development.

3

How to create a custom HttpException in NestJS?

Cevap

To create a custom exception, extend the HttpException class by calling super with the error message and HTTP status code. This approach allows defining business-specific exceptions for the application while respecting NestJS conventions. Custom exceptions facilitate maintenance and make code more expressive by giving meaningful names to different error situations.

4

Where to place the @Catch decorator for a global exception filter?

5

Which method must be implemented in a custom exception filter?

+17 mülakat soruları

Bir sonraki mülakatın için Node.js / NestJS'de uzmanlaş

Tüm sorulara, flashcards'a, teknik testlere, code review alıştırmalarına ve mülakat simülatörlerine eriş.

Ücretsiz başla