how to send error codes in nestjs app from controller?

You should use exception filters in your case instead.

In your case you’ll need:

throw new BadRequestException(error);

Or you can use

throw new HttpException('Forbidden', HttpStatus.FORBIDDEN);

That will return

{
  "statusCode": 403,
  "message": "Forbidden"
}

Docs: https://docs.nestjs.com/exception-filters

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)