🥅 server: handle no panda user on card create#791
Conversation
🦋 Changeset detectedLatest commit: 70ad3dc The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Summary of ChangesHello @cruzdanilo, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the server's card creation process by introducing robust error handling for unapproved Panda users. It ensures that when a user attempts to create a card but their associated Panda account lacks approval, the API responds with a precise 403 Forbidden status, providing clearer feedback and preventing unexpected system behavior. The changes also include a refactoring of error code constants for improved maintainability and new tests to cover these specific error conditions. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughRefactors Card API error handling to use inline string codes (e.g., "no panda", "no card"), replaces legacy response builders with direct schemas, adds a noUser helper for mapping user-resolution errors, and simplifies card creation/response shapes. Tests updated to match new error responses and additional edge cases added. Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client
participant Server as Server (card endpoint)
participant Panda as Panda/User Service
participant DB as Database
participant Sentry as Sentry
rect rgba(200,200,255,0.5)
Client->>Server: GET/POST /card
Server->>Panda: resolve user/credential
Panda-->>Server: user found / not found / unapproved
end
alt user found & approved
Server->>DB: read/create card
DB-->>Server: card payload
Server->>Client: 200/201 { ...card payload... }
else user missing or unapproved
Server->>Sentry: captureException (conditional)
Server->>Client: 403 { code: "no panda" }
else other error
Server->>Client: 500 { code: "internal_error" }
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 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 |
|
Sentry Issue: SERVER-J5 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #791 +/- ##
==========================================
+ Coverage 68.99% 69.31% +0.31%
==========================================
Files 207 207
Lines 7032 7175 +143
Branches 2222 2299 +77
==========================================
+ Hits 4852 4973 +121
- Misses 2001 2016 +15
- Partials 179 186 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
This pull request correctly handles a specific user not approved error from the Panda API during card creation by returning a 403 status, including specific error parsing and new tests. No specific vulnerabilities or critical issues were found. There are a couple of suggestions to improve code maintainability and clarity.
I am having trouble creating individual review comments. Click here to see my feedback.
server/api/card.ts (48-53)
The BadRequestCodes constant object was removed, and its values are now hardcoded as strings. Using constants for such values is generally better for maintainability as it prevents typos, provides a single source of truth, and makes the code easier to refactor. Since these codes are used in multiple places, I'd recommend re-introducing this constant object.
server/utils/panda.ts (71-93)
The error handling logic in this catch block is a bit complex due to manual string parsing and variable declarations. This can be simplified for better readability and robustness, reducing the chance of bugs if the upstream error format changes slightly.
} catch (error) {
if (error instanceof Error) {
const separator = error.message.indexOf(" ");
if (separator !== -1) {
const status = Number.parseInt(error.message.slice(0, separator), 10);
if (status === 403) {
try {
const payload = JSON.parse(error.message.slice(separator + 1)) as { error?: string; message?: string };
if (payload.error === "ForbiddenError" && payload.message === "User exists, but is not not approved") {
throw new Error("panda user not approved");
}
} catch {
// Not JSON or doesn't match, fall through to rethrow original error
}
}
}
}
throw error;
}|
Sentry Issue: SERVER-JC |
|
Sentry Issue: SERVER-JE |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bb37db14ab
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Issues attributed to commits in this pull requestThis pull request was merged and Sentry observed the following issues:
|
Summary by CodeRabbit
Bug Fixes
Tests
Chores