fix: handle 404 errors with contextual messages#121
fix: handle 404 errors with contextual messages#121angeloashmore wants to merge 6 commits intomainfrom
Conversation
Catch `NotFoundRequestError` in all commands that call repo-scoped API endpoints and display "Repository not found: <repo>" instead of an unhandled stack trace. Closes #118 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The `checkIsTypeBuilderEnabled` call and `syncSlices`/`syncCustomTypes` in `init.ts` were outside the try/catch, so a non-existent repo would still crash with a stack trace. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…found The checkIsTypeBuilderEnabled call already validates the repo exists before syncing. A 404 during sync would mean something else, so remove the incorrect NotFoundRequestError catch around those calls. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…g repo not found Split try/catch blocks in list-then-mutate commands so list-endpoint 404s say "Repository not found" and mutation-endpoint 404s say the entity-specific message (e.g. "Webhook not found"). Remove explicit 404 catches where ambiguous (locale-remove, repo-create) and add a generic NotFoundRequestError handler in index.ts as a fallback. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 1770965. Configure here.
| } catch (error) { | ||
| if (error instanceof NotFoundRequestError) { | ||
| throw new CommandError(`Locale not found: ${code}`); | ||
| } |
There was a problem hiding this comment.
Misleading error message from upsert 404 response
Low Severity
The second catch block reports Locale not found: ${code} when upsertLocale throws NotFoundRequestError. However, upsertLocale POSTs to repository/locales?repository=${repo} — the locale ID is in the request body, not the URL. A 404 from this endpoint indicates the repository (the only URL-level identifier) wasn't found, not the locale. Additionally, the locale's existence was already confirmed by the preceding getLocales call. The message here is inconsistent with the PR's intent and would confuse users by pointing them toward the wrong problem.
Reviewed by Cursor Bugbot for commit 1770965. Configure here.
Client functions that call repo-scoped endpoints (list/create operations) now catch 404s and rethrow with a "Repository not found" message on NotFoundRequestError. The central handler in index.ts prints the message when set, or falls back to the generic not-found text. This eliminates ~20 per-command try/catch blocks that were converting NotFoundRequestError into CommandError with the same repo-not-found message. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… new Simpler pattern: set message on the existing error and rethrow to preserve the original stack trace and response. Remove redundant throw statements where the catch block already ends with throw error. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>


Resolves:
Description
Adds user-friendly error messages when API calls return 404, distinguishing between "repository not found" and other not-found cases (e.g., webhook, token, locale).
Client functions that call repo-scoped endpoints now detect 404s and set a "Repository not found: {repo}" message on
NotFoundRequestError. The central error handler inindex.tsprints this message when set, or falls back to a generic not-found message. This eliminates repetitive per-command try/catch blocks.Checklist
Preview
How to QA 1
Run any command with a nonexistent repository name:
Verify that entity-not-found errors still show specific messages:
Footnotes
Please use these labels when submitting a review:
⚠️ #issue: Strongly suggest a change.
❓ #ask: Ask a question.
💡 #idea: Suggest an idea.
🎉 #nice: Share a compliment. ↩