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
| Property | Type |
|---|---|
message | HttpExceptionBodyMessage |
error | string |
statusCode | number |
Diagram
mermaidgraph 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
tsimport 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, andstatusCodefields when constructing standardized HTTP error responses. - Treat
messageasHttpExceptionBodyMessage; it may represent a single message or multiple validation messages. - Use valid HTTP status codes for
statusCodeand keeperroraligned 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?