Skip to content

RequestTimeoutException

reference
1 min readUpdated

Kind: Class

Source: packages/common/exceptions/request-timeout.exception.ts

Part of: Common

Defines an HTTP exception for Request Timeout type errors.

RequestTimeoutException represents an HTTP 408 Request Timeout error. Use it when a client request exceeds an allowed processing or response time, allowing NestJS exception filters to return a standardized timeout response.

Extends: HttpException

Diagram

mermaid
graph LR
  Client[HTTP Client] --> Controller[Controller / Service]
  Controller -->|Request exceeds time limit| Timeout[RequestTimeoutException]
  Timeout --> Filter[NestJS Exception Filter]
  Filter -->|HTTP 408 Request Timeout| Client

Usage

ts
import { Controller, Get, RequestTimeoutException } from '@nestjs/common';

@Controller('reports')
export class ReportsController {
  @Get()
  async generateReport() {
    const completedInTime = false;

    if (!completedInTime) {
      throw new RequestTimeoutException(
        'Report generation exceeded the allowed request time.',
      );
    }

    return { status: 'complete' };
  }
}

AI Coding Instructions

  • Throw RequestTimeoutException when the request cannot complete within an expected server-side time limit.
  • Prefer this exception over generic HttpException when the appropriate HTTP response is 408 Request Timeout.
  • Include a clear, client-safe error message; avoid exposing internal timing, infrastructure, or dependency details.
  • Let NestJS's built-in exception handling serialize the exception unless the application uses a custom global exception filter.
  • For long-running work, consider asynchronous job processing or background queues instead of repeatedly extending request timeouts.

Used by

1 reference from 1 file. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

Imported by (1)

  • DisconnectedClientControllerintegration/microservices/src/disconnected.controller.ts:12

Was this page helpful?

Download as PDF
RequestTimeoutException — NestJS head-to-head