fix: throw conflict error for duplicate roles/permissions#2845
fix: throw conflict error for duplicate roles/permissions#2845chronark merged 19 commits intounkeyed:mainfrom
Conversation
|
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
@Flo4604 is attempting to deploy a commit to the Unkey Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughThis pull request standardizes error handling across the application by replacing inconsistent error codes. In multiple API endpoints, tests, and documentation, error codes such as "NOT_UNIQUE" and "PRECONDITION_FAILED" have been updated or replaced with "CONFLICT" to better represent duplicate entry errors, with corresponding changes to HTTP status codes (e.g., from 412 to 409) and error messages. Additionally, an obsolete key route has been removed, and a new OpenAPI error response for HTTP 412 has been introduced. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant API
participant Database
Client->>API: Sends request to create/update record
API->>Database: Attempt to insert/update entry
Database-->>API: Returns duplicate entry error
API->>API: Catches DatabaseError and maps error code to "CONFLICT" (409)
API->>Client: Sends error response with status 409 and error code "CONFLICT"
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
Thank you for following the naming conventions for pull request titles! 🙏 |
apps/api/src/routes/v1_permissions_createPermission.error.test.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
apps/api/src/routes/v1_permissions_createRole.error.test.ts (1)
41-75: LGTM! Well-structured test for duplicate role handling.The test effectively validates the new conflict error handling for duplicate roles. Good use of typed requests and detailed error messages in assertions.
Consider adding assertions for the error response body to verify the correct error code and message. Example:
expect( errorResponse.status, `expected 409, received: ${JSON.stringify(errorResponse, null, 2)}`, ).toBe(409); +expect(errorResponse.body).toMatchObject({ + error: { + code: "CONFLICT", + message: expect.stringContaining("duplicate"), + docs: expect.stringContaining("unkey.dev/docs/api-reference/errors") + } +});
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
apps/api/src/routes/v1_identities_createIdentity.error.test.ts(1 hunks)apps/api/src/routes/v1_identities_updateIdentity.error.test.ts(3 hunks)apps/api/src/routes/v1_permissions_createPermission.error.test.ts(2 hunks)apps/api/src/routes/v1_permissions_createRole.error.test.ts(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
- apps/api/src/routes/v1_identities_createIdentity.error.test.ts
- apps/api/src/routes/v1_identities_updateIdentity.error.test.ts
- apps/api/src/routes/v1_permissions_createPermission.error.test.ts
🔇 Additional comments (1)
apps/api/src/routes/v1_permissions_createRole.error.test.ts (1)
3-3: LGTM! Good choice using node:crypto for UUID generation.Using the native
randomUUIDfunction is a good practice for generating unique test data.
What does this PR do?
PRECONDITION_FAILED, which pannes in the createIdentity endpoint.apps/api/src/routes/v1_keys_ami.tswhich was not being used as its a duplicate ofapps/api/src/routes/v1_keys_whoami.tsPRECONDITION_FAILEDPRECONDITION_FAILEDtoCONFLICTType of change
How should this be tested?
Running the createPermission and createRole tests.
Checklist
Required
pnpm buildpnpm fmtconsole.logsgit pull origin mainAppreciated
Summary by CodeRabbit