Programování
Pokročilý
Claude
Error handling middleware
Vytvoření centralizovaného error handling system pro API.
Prompt text
Délka: Střední
Vytvoř error handling middleware pro [FRAMEWORK] API.
**Requirements:**
**1. Error Types:**
- ValidationError (400)
- UnauthorizedError (401)
- ForbiddenError (403)
- NotFoundError (404)
- ConflictError (409)
- ServerError (500)
**2. Error Response Format:**
```json
{
"error": {
"code": "ERROR_CODE",
"message": "Human-readable",
"details": {},
"timestamp": "ISO",
"path": "/api/endpoint"
}
}
```
**3. Features:**
- Logging (different levels)
- Stack trace (dev only)
- Error monitoring (Sentry integration)
- Rate limit errors
- Graceful degradation
**4. Async error handling**
**Include:**
- Middleware implementation
- Custom error classes
- Usage examples
- Testing
Framework: [EXPRESS/FASTIFY/NESTJS]. Language: [TS/JS].
**Requirements:**
**1. Error Types:**
- ValidationError (400)
- UnauthorizedError (401)
- ForbiddenError (403)
- NotFoundError (404)
- ConflictError (409)
- ServerError (500)
**2. Error Response Format:**
```json
{
"error": {
"code": "ERROR_CODE",
"message": "Human-readable",
"details": {},
"timestamp": "ISO",
"path": "/api/endpoint"
}
}
```
**3. Features:**
- Logging (different levels)
- Stack trace (dev only)
- Error monitoring (Sentry integration)
- Rate limit errors
- Graceful degradation
**4. Async error handling**
**Include:**
- Middleware implementation
- Custom error classes
- Usage examples
- Testing
Framework: [EXPRESS/FASTIFY/NESTJS]. Language: [TS/JS].
Příklad použití
Vstup:
Vytvoř error handling pro Express API. Framework: Express + TypeScript. Include: custom errors, middleware, Sentry, logging (Winston), async wrapper.
Výstup:
Complete error system: Custom error classes (AppError base class, ValidationError extends with 400 status, etc.), async error wrapper (catchAsync HOF), central error middleware (checks instanceof, formats response, logs appropriately), Sentry integration (captures in production), Winston logger (different levels for dev/prod), graceful shutdown on unhandled errors. Usage examples: throw new ValidationError("Invalid email") → formatted 400 response. Tests: error scenarios covered. Dev mode: stack trace. Prod: clean messages, no internals exposed.
Kde použít tento prompt?
Najděte vhodné AI nástroje pro použití tohoto promptu a maximalizujte jeho efektivitu.
Podobné prompty
Advanced AI Features - Deep Dive do Pokročilých Funkcí
Komplexní průvodce pokročilými funkcemi AI nástrojů - od extended context a multimodality po tool use, streaming, a fine-tuning. Naučte se využívat plný potenciál moderních AI systémů.
Programování
Zobrazit
Algoritmus optimalizace
Optimalizace algoritmu z O(n²) na O(n log n) nebo lepší.
Programování
Zobrazit
API design s REST best practices
Návrh RESTful API s dokumentací a error handling.
Programování
Zobrazit
CI/CD pipeline setup
Konfigurace GitHub Actions / GitLab CI pipeline s testing a deployment.
Programování
Zobrazit
Objevte další AI prompty
Prozkoumejte naši sbírku Programování promptů a najděte ty, které vám pomohou dosáhnout lepších výsledků.