Skip to content

chore(ui,shared,localizations): Improve error handling when creating API keys#8056

Open
wobsoriano wants to merge 11 commits intomainfrom
rob/api-keys-usage-exceeded
Open

chore(ui,shared,localizations): Improve error handling when creating API keys#8056
wobsoriano wants to merge 11 commits intomainfrom
rob/api-keys-usage-exceeded

Conversation

@wobsoriano
Copy link
Member

@wobsoriano wobsoriano commented Mar 12, 2026

Description

  • Handles 403 (usage exceeded) and 409 (duplicate name) errors when creating API keys in the <APIKeys /> component
  • Add localized error messages for both cases

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Summary by CodeRabbit

  • New Features

    • Added localized error messages for API key creation to surface clear feedback for usage limits and name conflicts.
  • Bug Fixes

    • Improved error handling to distinguish API key creation failures (usage limit vs name conflict) and show appropriate localized messages.
  • Tests

    • Added integration tests validating both usage-limit and name-conflict error flows (including duplicated test cases).
  • Chores

    • Added a changeset to publish patch updates.

@vercel
Copy link

vercel bot commented Mar 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment Mar 13, 2026 3:42pm

Request Review

@changeset-bot
Copy link

changeset-bot bot commented Mar 12, 2026

🦋 Changeset detected

Latest commit: 5dfa779

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 21 packages
Name Type
@clerk/localizations Patch
@clerk/shared Patch
@clerk/ui Patch
@clerk/react Patch
@clerk/agent-toolkit Patch
@clerk/astro Patch
@clerk/backend Patch
@clerk/chrome-extension Patch
@clerk/clerk-js Patch
@clerk/expo-passkeys Patch
@clerk/expo Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/hono Patch
@clerk/msw Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/tanstack-react-start Patch
@clerk/testing Patch
@clerk/vue Patch

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

@wobsoriano wobsoriano changed the title chore(ui,shared,localization): Improve error handling when creating API keys chore(ui,shared,localizations): Improve error handling when creating API keys Mar 12, 2026
@wobsoriano wobsoriano marked this pull request as ready for review March 12, 2026 20:56
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: 3ec33c6a-694f-4a3a-9274-690d6f3bd51e

📥 Commits

Reviewing files that changed from the base of the PR and between 7041271 and 9dcc47c.

📒 Files selected for processing (1)
  • integration/tests/machine-auth/component.test.ts

📝 Walkthrough

Walkthrough

Adds a changeset file and introduces two new localization keys and corresponding type entries: api_key_name_already_exists and api_key_usage_exceeded. Updates the APIKeys component to map HTTP 403 to the api_key_usage_exceeded localization and HTTP 409 to the api_key_name_already_exists localization, and discards the return value of invalidateAll(). Adds integration tests validating the 409 name-conflict and 403 usage-limit API key error scenarios.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: improving error handling for API key creation across multiple packages (ui, shared, localizations) with localized messages for both usage-exceeded and name-conflict scenarios.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 12, 2026

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@8056

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@8056

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@8056

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@8056

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@8056

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@8056

@clerk/expo

npm i https://pkg.pr.new/@clerk/expo@8056

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@8056

@clerk/express

npm i https://pkg.pr.new/@clerk/express@8056

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@8056

@clerk/hono

npm i https://pkg.pr.new/@clerk/hono@8056

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@8056

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@8056

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@8056

@clerk/react

npm i https://pkg.pr.new/@clerk/react@8056

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@8056

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@8056

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@8056

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@8056

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@8056

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@8056

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@8056

commit: 5dfa779

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 `@packages/ui/src/components/APIKeys/APIKeys.tsx`:
- Around line 123-126: The 403 branch in APIKeys.tsx currently maps all
forbidden responses to the "usage exceeded" message; update the handler in the
block that checks err.status === 403 to inspect the backend error code (e.g.,
err?.data?.code or err?.body?.code) and only call
card.setError(t(localizationKeys('unstable__errors.api_key_usage_exceeded')))
when that code equals "token_quota_exceeded"; for other 403s call a generic
forbidden message (or a fallback like t(localizationKeys('errors.forbidden')))
and ensure err is safely null-checked before reading the code to avoid runtime
errors.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0715d523-4e31-4d5b-8073-facaf725b8f5

📥 Commits

Reviewing files that changed from the base of the PR and between a5aa803 and 5b7dfa9.

📒 Files selected for processing (5)
  • .changeset/cyan-elephants-roll.md
  • integration/tests/machine-auth/component.test.ts
  • packages/localizations/src/en-US.ts
  • packages/shared/src/types/localization.ts
  • packages/ui/src/components/APIKeys/APIKeys.tsx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant