Disable stack traces from graphql errors in NestJs

I am throwing this when the jwt-token has expired:

      throw new AuthenticationError('Token expired');

which comes from

import { AuthenticationError } from 'apollo-server-errors';

Every time a user is facing this, the stack trace for the exception appears in the logs as well. Not sure how to handle this, it is an expected exception to have every time a user need to refresh their jwt token. How do I disable the stack trace logging for these kinds of errors only?

Does it happen because the error is imported from apollo-server-errors and not one of the standard errors in @nestjs/common? I thing that using a regular exception from nestjs would cause other issues instead, since those are for http and not graphql specifically.

Read more here: Source link