Add community plugin: Elysia HTTP Exception #598
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🚨 Add Elysia HTTP Exception Plugin
Summary
This PR introduces a comprehensive HTTP exception handling plugin for Elysia, inspired by NestJS's HTTP Exception system. The plugin provides structured exception classes for all standard 4xx and 5xx HTTP status codes with type-safe error handling.
Motivation
While building applications with Elysia, I found myself repeatedly creating custom error handling patterns for different HTTP status codes. This led to inconsistent error responses and boilerplate code across projects.
Drawing inspiration from NestJS's elegant HTTP Exception system, I created this plugin to bring the same level of structure and consistency to Elysia applications.
What This Plugin Provides
✨ Features
throw
statements or thehttpException
decorator🎯 Available Exception Classes
4xx Client Errors:
BadRequestException
(400)UnauthorizedException
(401)ForbiddenException
(403)NotFoundException
(404)MethodNotAllowedException
(405)ConflictException
(409)UnprocessableEntityException
(422)TooManyRequestsException
(429)5xx Server Errors:
InternalServerErrorException
(500)NotImplementedException
(501)BadGatewayException
(502)ServiceUnavailableException
(503)GatewayTimeoutException
(504)Basic Usage Example
Response Examples
Simple string message:
Custom object data:
Alternative Usage: Decorator Pattern
Advanced Examples
Authentication & Authorization
Rate Limiting
File Upload Validation
Built-in Error Handling
The plugin automatically handles common Elysia errors:
Inspiration from NestJS
This plugin draws heavy inspiration from NestJS's HTTP Exception system, specifically:
NestJS References:
Package Information
elysia-http-exception
Installation
Testing & Quality
Why This Should Be Added
Community Impact
This plugin addresses a common pattern that many Elysia developers implement manually. By providing a standardized, well-tested solution, it can:
I believe this plugin would be a valuable addition to the official Elysia plugin ecosystem. It's production-ready, well-documented, and solves a real problem that many developers face when building APIs with Elysia.
Thank you for considering this contribution to the Elysia community! 🚀
Summary by CodeRabbit