PDMLab / http-problem-details

This library implements HTTP Problem details (RFC 7807) for HTTP APIs build with Node.js.
https://www.npmjs.com/package/http-problem-details
MIT License
48 stars 8 forks source link

Add guideline on how to use with nestjs #42

Open lekhasy opened 3 months ago

lekhasy commented 3 months ago

Nestjs is famous among nodejs API framework, it would be helpful to have a short section describe how to use this with nestjs. I tried to copy the code provided in readme but it does not work, I think other people might have the same experience.

FYI, this is what i have done:

async function bootstrap() { const app = await NestFactory.create(AppModule); const strategy = new DefaultMappingStrategy( new MapperRegistry() .registerMapper(new NotFoundErrorMapper())) app.use(HttpProblemResponse({ strategy })) await app.listen(3000); } bootstrap();


Expected result:

{ "status": 404, "title": "customer with id 123 could not be found.", "type": "http://tempuri.org/NotFoundError" }


Actual Result:

{ "statusCode": 500, "message": "Internal server error" }