Documentation Index
Fetch the complete documentation index at: https://mintlify.com/LizandroCanul/back_sdo/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The API uses NestJS’s built-in HTTP exceptions to provide standardized error responses. All exceptions follow a consistent JSON structure for easy client-side handling.Standard Error Response Format
All HTTP exceptions return this structure:Common HTTP Exceptions
BadRequestException (400)
Used for validation errors and invalid input.- Duplicate entries
- Invalid data format
- Business rule violations
- Already existing resources
/home/daytona/workspace/source/src/users/users.service.ts:161/home/daytona/workspace/source/src/users/users.service.ts:105
UnauthorizedException (401)
Used when authentication fails or credentials are invalid.- Invalid login credentials
- Missing JWT token
- Expired token
- Invalid token signature
/home/daytona/workspace/source/src/auth/auth.controller.ts:14
ForbiddenException (403)
Used when a user is authenticated but lacks permission to access a resource.- Accessing another user’s data
- Non-admin trying admin operations
- Modifying resources without ownership
- Role-based access denial
/home/daytona/workspace/source/src/users/users.controller.ts:52/home/daytona/workspace/source/src/users/users.controller.ts:66/home/daytona/workspace/source/src/users/users.controller.ts:89
NotFoundException (404)
Used when a requested resource doesn’t exist.- Entity not found by ID
- Resource deleted or never existed
- Invalid foreign key references
/home/daytona/workspace/source/src/users/users.service.ts:49/home/daytona/workspace/source/src/obras/obras.service.ts:115/home/daytona/workspace/source/src/dependencias/dependencias.service.ts:34
ConflictException (409)
Used when a request conflicts with the current state.- Unique constraint violations
- State conflicts (e.g., deleting an active record)
- Race conditions
/home/daytona/workspace/source/src/obras/obras.service.ts:1
Real-World Error Examples
Authentication Flow
Authorization Flow
Resource Operations
Permission Error Patterns
User Resource Protection
/home/daytona/workspace/source/src/users/users.controller.ts:45-54/home/daytona/workspace/source/src/users/users.controller.ts:58-68/home/daytona/workspace/source/src/users/users.controller.ts:81-91
Validation Errors
Validation errors are automatically handled by theValidationPipe and return 400 Bad Request:
Validation errors are configured in
main.ts:8-14 with the global ValidationPipe.Error Handling Best Practices
Be Specific
Use descriptive error messages that help users understand what went wrong.
Choose Correct Status
- 400: Bad input
- 401: Not authenticated
- 403: Not authorized
- 404: Not found
- 409: Conflict
Avoid Exposing Internals
Don’t leak database errors or stack traces to clients in production.
Consistent Messages
Keep error messages in the same language throughout the API (Spanish in this project).
Quick Reference
401 vs 403: What's the difference?
401 vs 403: What's the difference?
401 Unauthorized: User is not logged in or token is invalid.403 Forbidden: User is logged in but doesn’t have permission.
400 vs 409: When to use each?
400 vs 409: When to use each?
400 Bad Request: General validation errors or bad input.409 Conflict: Specific state conflicts (usually from database constraints).
How to handle database errors?
How to handle database errors?
Catch database errors and convert to appropriate HTTP exceptions:
HTTP Status Code Summary
| Status Code | Exception | Use Case | Example |
|---|---|---|---|
| 400 | BadRequestException | Invalid input, validation errors | ”Email ya registrado” |
| 401 | UnauthorizedException | Authentication failure | ”Credenciales inválidas” |
| 403 | ForbiddenException | Permission denied | ”No tienes permiso” |
| 404 | NotFoundException | Resource not found | ”Obra 123 no encontrada” |
| 409 | ConflictException | State conflict | ”Clave única duplicada” |
| 500 | InternalServerErrorException | Server error | ”Error del servidor” |
Next Steps
Database Schema
Learn about entity relationships
Validation
Understand request validation