NestJS · Middle · Question 27 of 75
Where should database errors like unique violations be translated into HTTP errors?
- 1Let them reach the client as 500 with the SQL message
- 2In the DTO
- ✓Correct answer: In a dedicated place, e.g. the service or an exception filter, mapping them to
ConflictException(409)
Explanation
Never leak SQL or stack traces. A filter for ORM errors keeps the mapping in one place.