Posts

Showing posts with the label nestjs

Mysterious `The “modules” key in the @Module() decorator is deprecated`

Mysterious `The “modules” key in the @Module() decorator is deprecated` Running a nestjs application and the console shows: WARNING!! The "modules" key in the @Module() decorator is deprecated and will be removed within next major release. Use the "imports" key instead. My modules are declared like : @Module({ imports: [UserModule], providers: [AuthService, JwtStrategy], controllers: [AuthController] }) export class AuthModule {} I also executed "find in path" for the word modules to ensure there is no modules in my code. modules modules Any ideas? 1 Answer 1 I had this issue with older versions of NestJs. Upgrading package.json helped. Make sure that you use up-to-date versions ^5.0.0 for all @nestjs/* packages. By clicking "Post Your Answer", you acknowledge that you have read our updated terms of ser...

NestJS error handling approach

NestJS error handling approach While using NestJS to create API's I was wondering which is the best way to handle errors/exception. I have found two different approaches : throw new Error() catch HttpException BadRequestException ForbiddenException HttpException There are pros and cons to both approeaches: Error HttpException Http I was wondering, which one (if any) os the "nest js" way of doing it ? How do you handle this matter? 1 Answer 1 You may want to bind services not only to HTTP interface, but also for GraphQL or any other interface. So it is better to cast business-logic level exceptions from services to Http-level exceptions (BadRequestException, ForbiddenException) in controllers. In the simpliest way it could look like import { BadRequestException, Injectable } from '@nestjs/common'; @Injectable() export class HttpHelperService { async transformExceptions(action:...