title: NestJS throw http exepction from guard (export as library module)
body: <p>I'm making a nestjs library where I include a guard as part of the module,</p>
  <p>I try to throw http error from guard, but the context was lost in controller it will just throw 500 instead.</p>
  <p>It works fine if I import the library as source code instead of dist build.</p>
  <pre class="lang-js prettyprint-override"><code>@Injectable()
  export class SignedUrlGuard implements CanActivate {
      constructor(
          private readonly signedUrlService: SignedUrlService,
      ) { }
  
      canActivate(
          context: ExecutionContext,
      ): boolean | Promise&lt;boolean&gt; | Observable&lt;boolean&gt; {
          const request = context.switchToHttp().getRequest();
          return this.validateRequest(request, request.query);
      }
  
      private validateRequest(request: Request, query: Record&lt;string, string&gt;): boolean {
          try {
              return this.signedUrlService.isSignatureValid(request, query)
          } catch (error) {
              throw new ForbiddenException('Invalid url ,with custom error message')
          }
      }
  }
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>&quot;devDependencies&quot;: {
      &quot;@nestjs/common&quot;: &quot;^7.4.4&quot;,
      &quot;@nestjs/core&quot;: &quot;^7.4.4&quot;,
      &quot;@types/express&quot;: &quot;^4.17.8&quot;,
      &quot;@types/node&quot;: &quot;^14.14.2&quot;,
      &quot;reflect-metadata&quot;: &quot;^0.1.13&quot;,
      &quot;rxjs&quot;: &quot;^6.6.3&quot;,
      &quot;typescript&quot;: &quot;^4.0.3&quot;,
      &quot;prettier&quot;: &quot;^2.1.2&quot;,
      &quot;eslint&quot;: &quot;^7.12.0&quot;,
      &quot;eslint-config-prettier&quot;: &quot;^6.14.0&quot;,
      &quot;@typescript-eslint/eslint-plugin&quot;: &quot;^4.5.0&quot;,
      &quot;@typescript-eslint/parser&quot;: &quot;^4.5.0&quot;
    },
    &quot;peerDependencies&quot;: {
      &quot;@nestjs/common&quot;: &quot;^7.4.4&quot;,
      &quot;@nestjs/core&quot;: &quot;^7.4.4&quot;,
      &quot;reflect-metadata&quot;: &quot;^0.1.13&quot;
    }
  </code></pre>
  <p>tsconfig</p>
  <pre class="lang-js prettyprint-override"><code>{
    &quot;compilerOptions&quot;: {
      &quot;module&quot;: &quot;commonjs&quot;,
      &quot;declaration&quot;: true,
      &quot;strict&quot;: true,
      &quot;noImplicitAny&quot;: false,
      &quot;removeComments&quot;: true,
      &quot;noLib&quot;: false,
      &quot;emitDecoratorMetadata&quot;: true,
      &quot;experimentalDecorators&quot;: true,
      &quot;target&quot;: &quot;es2019&quot;,
      &quot;sourceMap&quot;: false,
      &quot;outDir&quot;: &quot;./dist&quot;,
      &quot;rootDir&quot;: &quot;./lib&quot;,
      &quot;skipLibCheck&quot;: true
    },
    &quot;include&quot;: [&quot;lib/**/*&quot;],
    &quot;exclude&quot;: [&quot;node_modules&quot;, &quot;dist&quot;, &quot;test&quot;, &quot;**/*spec.ts&quot;]
  }
  </code></pre>
  <p>You can check full code here
  <a href="https://github.com/vh13294/nestjs-signed-url" rel="nofollow noreferrer">https://github.com/vh13294/nestjs-signed-url</a></p>