fix: sanitize server error responses to prevent internal detail leaks
Browse files- backend/main.py +7 -4
- backend/pipeline.py +4 -7
backend/main.py
CHANGED
|
@@ -221,13 +221,16 @@ async def analyze_crop_image(
|
|
| 221 |
except HTTPException:
|
| 222 |
raise
|
| 223 |
except ValueError as ve:
|
| 224 |
-
logger.error(f"Image processing
|
| 225 |
-
raise HTTPException(
|
|
|
|
|
|
|
|
|
|
| 226 |
except Exception as e:
|
| 227 |
-
logger.exception(f"
|
| 228 |
raise HTTPException(
|
| 229 |
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
| 230 |
-
detail=
|
| 231 |
)
|
| 232 |
|
| 233 |
|
|
|
|
| 221 |
except HTTPException:
|
| 222 |
raise
|
| 223 |
except ValueError as ve:
|
| 224 |
+
logger.error(f"Image processing error: {ve}")
|
| 225 |
+
raise HTTPException(
|
| 226 |
+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
| 227 |
+
detail="Server Error. Please try again later."
|
| 228 |
+
)
|
| 229 |
except Exception as e:
|
| 230 |
+
logger.exception(f"Inference failure: {e}")
|
| 231 |
raise HTTPException(
|
| 232 |
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
| 233 |
+
detail="Server Error. Please try again later."
|
| 234 |
)
|
| 235 |
|
| 236 |
|
backend/pipeline.py
CHANGED
|
@@ -209,10 +209,8 @@ class PureGeminiInferenceEngine:
|
|
| 209 |
return cached_resp
|
| 210 |
|
| 211 |
if not self.is_configured():
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
"कृपया Hugging Face Space Settings -> Secrets में GEMINI_API_KEY सेट करें ताकि ऑनलाइन AI Vision सक्रिय हो सके।"
|
| 215 |
-
)
|
| 216 |
|
| 217 |
payload = {
|
| 218 |
"contents": [
|
|
@@ -295,9 +293,8 @@ class PureGeminiInferenceEngine:
|
|
| 295 |
|
| 296 |
# 4. If all models failed or busy
|
| 297 |
if raw_text is None:
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
)
|
| 301 |
|
| 302 |
# 5. Robust Self-Healing JSON parsing
|
| 303 |
try:
|
|
|
|
| 209 |
return cached_resp
|
| 210 |
|
| 211 |
if not self.is_configured():
|
| 212 |
+
logger.error("Gemini API Key is not configured on the backend server.")
|
| 213 |
+
raise RuntimeError("Server Error. Please try again later.")
|
|
|
|
|
|
|
| 214 |
|
| 215 |
payload = {
|
| 216 |
"contents": [
|
|
|
|
| 293 |
|
| 294 |
# 4. If all models failed or busy
|
| 295 |
if raw_text is None:
|
| 296 |
+
logger.error(f"All Gemini models exhausted or timed out ({last_error})")
|
| 297 |
+
raise RuntimeError("Server Error. Please try again later.")
|
|
|
|
| 298 |
|
| 299 |
# 5. Robust Self-Healing JSON parsing
|
| 300 |
try:
|