From 90600cb32675819a47e57374432f786f3ca6dc2b Mon Sep 17 00:00:00 2001 From: Nithin Gowda Date: Mon, 13 Apr 2026 16:10:56 +0530 Subject: [PATCH 1/2] Improve API error handling documentation in development guide --- development.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/development.md b/development.md index 7879ffcdbc..0c6086f8b5 100644 --- a/development.md +++ b/development.md @@ -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. From b80957e4671011b191082d9de38c1408cee9a5fb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Mon, 13 Apr 2026 10:43:26 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=8E=A8=20Auto=20format=20and=20update?= =?UTF-8?q?=20with=20pre-commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- development.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/development.md b/development.md index 0c6086f8b5..d232cb5fe4 100644 --- a/development.md +++ b/development.md @@ -209,10 +209,10 @@ Instead of returning plain text errors, structured JSON responses improve client ### 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 +- 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)