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].
Interaktivní tvůrce

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.

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ů.