1

It seems like by default NestJS or node.js+express invokes a controller that had a timeout.

The result is that the controller is being called again and again every 2 minutes, how can that be disabled?

The required result should be throw HttpExeption of timeout.

I saw suggestions to extend the timeout length, I would like to keep the timeout but respond with an exception.

noam steiner
  • 4,034
  • 3
  • 27
  • 42

1 Answers1

0

To solve this I added a timeout handler to the response to throw an exception, otherwise, it would invoke again the controller method.

main.ts:

import { HttpException, HttpStatus } from '@nestjs/common';

app.use((req: Request, res: Response, next: NextFunction) => {
        const minute = 60 * 1000;
        req.setTimeout(
            5 * minute,
            () => *emphasized text*{ throw new HttpException('Requset timeout', HttpStatus.REQUEST_TIMEOUT); }
        );
        next();
    });
noam steiner
  • 4,034
  • 3
  • 27
  • 42