{ "success": false, "message": "Invalid user ID", "code": 400, "field": "id", "info": { "name": "Solicitud incorrecta", "category": "Error del cliente", "description": "La solicitud no pudo ser procesada debido a errores de sintaxis", "possibleCauses": [ "Parámetros faltantes o inválidos", "Formato de datos incorrecto" ] }}
Not Found (404)
{ "success": false, "message": "User not found", "code": 404, "userId": "999", "info": { "name": "No encontrado", "category": "Error del cliente", "description": "El recurso solicitado no existe", "possibleCauses": [ "URL incorrecta", "Recurso eliminado o movido" ] }}
StatusFlow also provides HTTP exception classes for cleaner error handling:
import { BadRequestException, NotFoundException, httpErrorMiddleware} from 'status-flow';// Throw exceptions directlyapp.get('/api/products/:id', (req, res) => { if (!req.params.id) { throw new BadRequestException('Product ID is required'); } const product = findProduct(req.params.id); if (!product) { throw new NotFoundException('Product not found'); } res.json(product);});// Use the httpErrorMiddleware insteadapp.use(httpErrorMiddleware);
The statusFlowMiddleware provides bilingual responses with rich metadata, while httpErrorMiddleware provides simpler responses. Choose based on your needs.