Search code examples
javascriptnode.jstypescriptnestjs

Throw HttpException at service in nestjs


Is it good way to throw Http Exeption at service in nestjs? What is the best way to processing error at service in nestjs?


Solution

  • From experience, it's best practice to throw HTTPExceptions in the controller logic manually or have an exception filter automatically catch exceptions. Services should be reusable pieces of functionality that can sometimes be used in non-http contexts.

    Having http logic in the service layer feels like an anti-pattern.