Description
The webhook handler needs better error handling and logging to debug issues in production.
Current Issues
- No request logging - Cannot see what Lark is actually sending
- Silent failures - Errors may be swallowed without logging
- No response logging - Cannot verify what's being returned to Lark
Recommended Improvements
1. Add detailed request logging
@app.post("/webhook/event")
async def webhook_event(request: Request):
# Log full request for debugging
body_bytes = await request.body()
headers = dict(request.headers)
logger.info(f"=== WEBHOOK REQUEST ===")
logger.info(f"Headers: {json.dumps(headers, default=str)}")
logger.info(f"Body: {body_bytes.decode()[:1000]}")
try:
body = json.loads(body_bytes)
except json.JSONDecodeError as e:
logger.error(f"Failed to parse JSON: {e}")
logger.error(f"Raw body: {body_bytes.decode()}")
raise HTTPException(status_code=400, detail="Invalid JSON")
2. Add response logging
response_data = {"status": "processed"}
logger.info(f"=== WEBHOOK RESPONSE ===")
logger.info(f"Response: {json.dumps(response_data)}")
return JSONResponse(content=response_data)
3. Add structured error handling
except Exception as e:
logger.exception(f"Webhook processing error: {e}")
# Still return 200 to Lark to prevent retries
return JSONResponse(
content={"status": "error", "error": str(e)},
status_code=200
)
Also Add
- Health check endpoint that shows recent webhook activity
- Endpoint to view recent logs (for debugging)
- Sentry or similar error tracking integration
Priority
MEDIUM - Essential for debugging production issues
Description
The webhook handler needs better error handling and logging to debug issues in production.
Current Issues
Recommended Improvements
1. Add detailed request logging
2. Add response logging
3. Add structured error handling
Also Add
Priority
MEDIUM - Essential for debugging production issues