Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions development.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,53 @@ ruff-format..............................................................Passed
biome check..............................................................Passed
```

## Error Handling Best Practices for APIs

When developing APIs, especially for production systems, it's important to handle errors in a consistent and structured way.

### Example using FastAPI

from fastapi import HTTPException

def get_item(item_id: int):
if item_id != 1:
raise HTTPException(
status_code=404,
detail="Item not found"
)
return {"item": "valid"}

### Structured Error Response

Instead of returning plain text errors, structured JSON responses improve client-side handling:

{
"detail": {
"error": "Item not found",
"code": 404
}
}

### Recommendations

- Use appropriate HTTP status codes (e.g., 400, 404, 500)
- Return structured JSON error responses
- Avoid exposing internal implementation details
- Log errors for debugging and monitoring

### Optional: Confidence-Based Handling (Advanced)

{
"detail": {
"error": "Low confidence prediction",
"confidence": 0.62,
"action": "Require human review"
}
}

This pattern is useful when integrating human-in-the-loop or safety-critical systems.


## URLs

The production or staging URLs would use these same paths, but with your own domain.
Expand Down
Loading