Kind: Class
Source: packages/common/exceptions/http-version-not-supported.exception.ts
Part of: Common
Defines an HTTP exception for Http Version Not Supported type errors.
HttpVersionNotSupportedException represents an HTTP 505 error, indicating that the server does not support the HTTP protocol version used by the client request. It extends Nest's HTTP exception system so the framework can serialize the error into a standard HTTP response.
Extends: HttpException
Diagram
mermaidgraph LR Client[Client Request] --> VersionCheck[HTTP Version Validation] VersionCheck -->|Supported| Handler[Request Handler] VersionCheck -->|Unsupported| Exception[HttpVersionNotSupportedException] Exception --> Response[HTTP 505 Response]
Usage
tsimport { Controller, Get } from '@nestjs/common';
import { HttpVersionNotSupportedException } from '@nestjs/common';
@Controller('protocol')
export class ProtocolController {
@Get()
getProtocolInfo(): string {
const clientHttpVersion = 'HTTP/0.9';
if (clientHttpVersion !== 'HTTP/1.1' && clientHttpVersion !== 'HTTP/2') {
throw new HttpVersionNotSupportedException(
`HTTP version "${clientHttpVersion}" is not supported.`,
);
}
return 'Supported HTTP version.';
}
}
AI Coding Instructions
- Throw
HttpVersionNotSupportedExceptionwhen request processing detects an unsupported HTTP protocol version. - Provide a clear message or response body that identifies the unsupported version without exposing sensitive server configuration.
- Prefer framework-level protocol validation when available; use this exception for application-specific compatibility checks.
- Do not use this exception for malformed requests or unsupported media types; use the corresponding HTTP exception type instead.
Was this page helpful?