feat(http): add error handling for invalid HTTP methods

- Introduce `InvalidHttpMethodError` for unrecognized HTTP methods.
- Enhance type safety in `HttpKernel` by using generic contexts.
- Update `ResponseDecorator` to accept context for enriched responses.

Signed-off-by: Max P. <Mail@MPassarello.de>
This commit is contained in:
2025-05-07 12:35:41 +02:00
parent a236fa7c97
commit ba7aa79f56
3 changed files with 47 additions and 16 deletions

View File

@@ -0,0 +1,25 @@
/**
* Represents an error thrown when an incoming HTTP method
* is not among the recognized set of valid HTTP methods.
*
* This is typically used in routers or request dispatchers
* to enforce allowed methods and produce 405-like behavior.
*/
export class InvalidHttpMethodError extends Error {
/**
* The invalid method that triggered this error.
*/
public readonly method: unknown;
/**
* A fixed HTTP status code representing "Method Not Allowed".
*/
public readonly status: number = 405;
constructor(method: unknown) {
const label = typeof method === 'string' ? method : '[non-string]';
super(`Unsupported HTTP method: ${label}`);
this.name = 'InvalidHttpMethodError';
this.method = method;
}
}