Improve GraphQL and backend connectivity error messaging in frontend#4421
Improve GraphQL and backend connectivity error messaging in frontend#4421hassaansaleem28 wants to merge 2 commits intoOWASP:mainfrom
Conversation
Signed-off-by: Muhammad Hassaan Saleem <iamhassaans@gmail.com>
WalkthroughThe PR improves error handling and user messaging when the GraphQL client is not configured. Changes include: adding optional timeout configuration to the global error handler, introducing a GraphQL connection error notification mechanism, and replacing the generic error message with a detailed setup guide explaining environment variables and backend service requirements. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
frontend/src/utils/helpers/apolloClient.ts (1)
7-22: Reset one-time GraphQL connection toast after recovery.On Line 14, the guard is latched permanently. After one outage, later outages in the same session won’t show the connectivity guidance again. Consider resetting after a successful request.
Proposed refactor
let hasShownGraphQLConnectionError = false @@ fetch: async (uri, options) => { try { - return await fetch(uri, options) + const response = await fetch(uri, options) + // Backend is reachable again; allow future outage notifications. + hasShownGraphQLConnectionError = false + return response } catch (error) { notifyGraphQLConnectionError() throw error } },🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@frontend/src/utils/helpers/apolloClient.ts` around lines 7 - 22, The code latches hasShownGraphQLConnectionError permanently in notifyGraphQLConnectionError so subsequent outages in the same session never re-show the toast; modify the Apollo client success path to reset that latch after recovery by setting hasShownGraphQLConnectionError = false when a GraphQL request succeeds (e.g., in the Apollo link response handler or the fetch/execute success callback that you use when creating the client). Update the relevant places (the notifyGraphQLConnectionError function remains the same) and ensure the reset occurs on any successful response or onError recovery path so the toast can reappear for future outages.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@frontend/src/utils/helpers/apolloClient.ts`:
- Around line 7-22: The code latches hasShownGraphQLConnectionError permanently
in notifyGraphQLConnectionError so subsequent outages in the same session never
re-show the toast; modify the Apollo client success path to reset that latch
after recovery by setting hasShownGraphQLConnectionError = false when a GraphQL
request succeeds (e.g., in the Apollo link response handler or the fetch/execute
success callback that you use when creating the client). Update the relevant
places (the notifyGraphQLConnectionError function remains the same) and ensure
the reset occurs on any successful response or onError recovery path so the
toast can reappear for future outages.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 99625a4e-9a57-4451-a67c-e6d2bff6f217
📒 Files selected for processing (3)
frontend/src/app/global-error.tsxfrontend/src/utils/helpers/apolloClient.tsfrontend/src/wrappers/provider.tsx
|



Proposed change
Resolves #4308
Summary
This PR improves frontend error handling when GraphQL is not configured or if the backend is not running, so new contributors receive clearer setup guidance during local onboarding.
BEFORE:
AFTER:
When backend is not running:

Checklist
make check-testlocally: all warnings addressed, tests passed