fix(gateway): catch all async exceptions in enrich/hints; add LLM provider diagnostic log
Root causes identified for the persistent "fail to fetch" / silent hang issues:
1. `getRes.json()` in runHostedProposalEnrichAndPost and runHostedProposalReviewHintsJob had no try-catch. When the canister returns a 200 with invalid JSON (e.g. the PROPOSAL-LIFECYCLE.md proposal whose large body breaks the canister's JSON serializer), the SyntaxError propagates uncaught through the async Express 4 handler. Express 4 does NOT automatically catch unhandled async rejections, so the request hangs until the Netlify Lambda timeout. Netlify then returns an HTML 504 without CORS headers, which the browser blocks as a CORS violation (TypeError: Failed to fetch). Fix: wrap every fetch() and .json() call in try-catch and return { ok: false, ... }.
2. The top-level enrich Express handler had no try-catch. Any uncaught exception from loadHostedProposalLlmPrefs, resolveHostedActorRole, or other async work would silently hang the Lambda. Wrapping the full handler body in try-catch ensures every failure path returns a JSON error response, never a silent hang.
3. maybeScheduleHostedProposalReviewHints inside proxyToCanister could theoretically throw and abort the primary proxy response. Wrapped in try-catch with error logging.
4. Add a console.log in the enrich handler logging the LLM provider (openai / anthropic / ollama(NO KEY)). This appears in Netlify function logs and immediately confirms whether OPENAI_API_KEY is being picked up by the Lambda invocation.
These fixes mean: - Enrich on a proposal with bad canister JSON now returns HTTP 502 UPSTREAM_JSON with a descriptive message, not a Lambda timeout. - The LLM provider log line in Netlify → Logs → Functions → gateway confirms key pickup. - No failure in the hints path can crash the proposal-create response.
0 comments
muse hub commit comment sha256:c7907553852c44f92b615166b7635f2f528c2765f5f6077ea1de3b97e692c794 --body "your comment"
No comments yet. Be the first to start the discussion.