title: nestjs: How to throw an AuthenticationError when I use GraphQL
body: <p>I write the <code>GqlAuthGuard</code> module, but it always throw an <code>UnauthorizedException</code> when JWT expired or illegal. It will lead to an error in stacktrace.</p>
  
  <p>I want to throw <code>AuthenticationError</code>(from apollo-server-express).</p>
  
  <p>How can I do it?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>import { Injectable, ExecutionContext } from '@nestjs/common'
  import { AuthGuard } from '@nestjs/passport'
  import { GqlExecutionContext } from '@nestjs/graphql'
  
  @Injectable()
  export class GqlAuthGuard extends AuthGuard('jwt') {
    public getRequest(context: ExecutionContext) {
      const ctx = GqlExecutionContext.create(context)
      return ctx.getContext().req
    }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p><a href="https://i.stack.imgur.com/JJmUC.jpg" rel="nofollow noreferrer">GraphQL Authorization Error</a></p>