Skip to content

HttpExceptionBody

reference
1 min readUpdated

Kind: Interface

Source: packages/common/interfaces/http/http-exception-body.interface.ts

Part of: Common

HttpExceptionBody defines the standardized payload returned for HTTP exceptions. It combines a human-readable message, an error category string, and the numeric HTTP statusCode so clients can reliably inspect failed responses.

Properties

PropertyType
messageHttpExceptionBodyMessage
errorstring
statusCodenumber

Diagram

mermaid
graph LR
  A[HTTP Exception] --> B[HttpExceptionBody]
  B --> C[message: HttpExceptionBodyMessage]
  B --> D[error: string]
  B --> E[statusCode: number]
  C --> F[Client-facing error details]
  D --> G[Error category]
  E --> H[HTTP status code]

Usage

ts
import type { HttpExceptionBody } from './http-exception-body.interface';

const responseBody: HttpExceptionBody = {
  message: ['Email must be valid', 'Password must contain 8 characters'],
  error: 'Bad Request',
  statusCode: 400,
};

function handleError(body: HttpExceptionBody) {
  console.error(`${body.statusCode} ${body.error}`, body.message);
}

handleError(responseBody);

AI Coding Instructions

  • Preserve the message, error, and statusCode fields when constructing standardized HTTP error responses.
  • Treat message as HttpExceptionBodyMessage; it may represent a single message or multiple validation messages.
  • Use valid HTTP status codes for statusCode and keep error aligned with the corresponding error category.
  • Prefer this interface for serialized exception response bodies rather than exposing internal error objects or stack traces.

Was this page helpful?

Download as PDF
HttpExceptionBody — NestJS head-to-head