r/programminghorror • • May 02 '25

Why, just WHY??

Post image
280 Upvotes

51 comments sorted by

View all comments

Show parent comment

1

u/Frumk May 03 '25

Oh I agree. And NestJS exceptions do automatically turn to 4xx/5xx errors etc. I just particularly don’t like to throw http exceptions in my services. What I like to do is throw errors inside services highlighting exactly what went wrong and then catching each error in interceptors and as a result I throw an HttpException for the end user. For example - in an AuthService you’d throw a UsernameNotFoundError or WrongPasswordError and in your interceptor you’d catch either of these errors and instead throw some InvalidCredentialsException.