CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl-labs/nestjs-best-practices

NestJS patterns -- modules, DI, exception filters, validation pipes, guards, interceptors, testing, config

98

1.36x
Quality

89%

Does it follow best practices?

Impact

100%

1.36x

Average score across 12 eval scenarios

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

task.mdevals/scenario-4/

Product Catalog API Error Handling and Validation

Problem/Feature Description

A retail startup has a NestJS product catalog API. Their frontend team has complained that error responses from the API come back in inconsistent shapes -- sometimes { statusCode, message }, sometimes a raw stack trace, and sometimes an empty body for unhandled exceptions. This is making it hard to write generic error-handling logic in their React app.

The team wants:

  1. A single, predictable error shape for all failures regardless of whether they originate from a thrown HttpException (like a 404 for a missing product) or from an unexpected runtime error (like a null pointer or DB connection failure). Unknown errors should be logged to the console before the 500 response is sent.
  2. Global input validation that strips unknown properties and auto-transforms types.
  3. A POST endpoint for creating products with a validated DTO (name: non-empty string, price: positive number, category: string).

Your job is to implement the global exception filter, validation configuration, and product creation endpoint. Write the full main.ts, exception filter, and product module files. A stub service is sufficient.

Output Specification

Produce TypeScript source files in a products-api/src/ directory:

  • main.ts -- bootstrap with global exception filter and validation pipe configured
  • common/filters/all-exceptions.filter.ts -- the global exception filter
  • app.module.ts -- root module
  • products/products.module.ts -- products feature module
  • products/products.controller.ts -- controller with GET /:id and POST endpoints
  • products/products.service.ts -- stub service
  • products/dto/create-product.dto.ts -- DTO with validation decorators

Do not run npm install or start the server.

evals

tile.json