bapi143 commited on
Commit
95f33ab
·
1 Parent(s): 28986c6

fix: sanitize server error responses to prevent internal detail leaks

Browse files
Files changed (2) hide show
  1. backend/main.py +7 -4
  2. 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 validation error: {ve}")
225
- raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=str(ve))
 
 
 
226
  except Exception as e:
227
- logger.exception(f"Gemini inference failure: {e}")
228
  raise HTTPException(
229
  status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
230
- detail=f"Gemini analysis service encountered an error: {str(e)}"
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
- raise ValueError(
213
- "Hugging Face Cloud Server par Google Gemini Vision AI Key कॉन्फ़िगर नहीं है। "
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
- raise RuntimeError(
299
- f"Google Gemini AI Vision सर्वर अभी अत्यधिक व्यस्त है ({last_error})। कृपया 10-15 सेकंड बाद पुनः प्रयास करें।"
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: