Fix: resolve 'undefined' lobbyID in private battle creation#166
Conversation
|
@hansikareddy29 is attempting to deploy a commit to the aviralsaxena16's projects Team on Vercel. A member of the Team first needs to authorize it. |
🎉 Thanks for Your Contribution to CanonForces!
|
WalkthroughThe changes enhance error handling and validation throughout the battle creation flow. The client-side StartScreen component now validates API responses before navigation, the create endpoint validates roomId generation with detailed error messages, and the lobby page adds explicit handling for invalid room IDs with improved logging. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 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.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/pages/api/quiz/battle/create.ts`:
- Around line 25-27: The catch block in the room creation API (the handler in
create.ts that currently logs and returns error.message) exposes internal error
details to clients; change it to log the full error server-side (keep
console.error('[API_BATTLE_CREATE] Error creating room:', error)) but return a
generic client-safe message in the JSON response (e.g., { error: 'Failed to
create room. Please try again later.' }) and remove any use of error.message in
res.status(...).json; ensure the res call uses the same handler name/context
(the create room API handler) and preserves the 500 status.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 77d205c2-5143-4973-9245-50a16d651507
📒 Files selected for processing (3)
src/components/quiz/StartScreen.tsxsrc/pages/api/quiz/battle/create.tssrc/pages/quiz/lobby/[roomId].tsx
| } catch (error: any) { | ||
| console.error('[API_BATTLE_CREATE] Error creating room:', error.message || error); | ||
| return res.status(500).json({ error: error.message || 'Failed to create room. Please ensure Redis is configured.' }); |
There was a problem hiding this comment.
Avoid returning raw exception messages to clients.
error.message can expose backend internals (e.g., Redis connection details). Keep detailed errors in logs and return a generic client-safe message.
Suggested fix
- } catch (error: any) {
- console.error('[API_BATTLE_CREATE] Error creating room:', error.message || error);
- return res.status(500).json({ error: error.message || 'Failed to create room. Please ensure Redis is configured.' });
+ } catch (error: unknown) {
+ const message = error instanceof Error ? error.message : String(error);
+ console.error('[API_BATTLE_CREATE] Error creating room:', message);
+ return res.status(500).json({ error: 'Failed to create room. Please try again.' });
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| } catch (error: any) { | |
| console.error('[API_BATTLE_CREATE] Error creating room:', error.message || error); | |
| return res.status(500).json({ error: error.message || 'Failed to create room. Please ensure Redis is configured.' }); | |
| } catch (error: unknown) { | |
| const message = error instanceof Error ? error.message : String(error); | |
| console.error('[API_BATTLE_CREATE] Error creating room:', message); | |
| return res.status(500).json({ error: 'Failed to create room. Please try again.' }); | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/pages/api/quiz/battle/create.ts` around lines 25 - 27, The catch block in
the room creation API (the handler in create.ts that currently logs and returns
error.message) exposes internal error details to clients; change it to log the
full error server-side (keep console.error('[API_BATTLE_CREATE] Error creating
room:', error)) but return a generic client-safe message in the JSON response
(e.g., { error: 'Failed to create room. Please try again later.' }) and remove
any use of error.message in res.status(...).json; ensure the res call uses the
same handler name/context (the create room API handler) and preserves the 500
status.
Summary by CodeRabbit