Skip to content

fix: handle 404 errors with contextual messages#121

Draft
angeloashmore wants to merge 6 commits intomainfrom
aa/not-found-error
Draft

fix: handle 404 errors with contextual messages#121
angeloashmore wants to merge 6 commits intomainfrom
aa/not-found-error

Conversation

@angeloashmore
Copy link
Copy Markdown
Member

@angeloashmore angeloashmore commented Apr 11, 2026

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 in index.ts prints this message when set, or falls back to a generic not-found message. This eliminates repetitive per-command try/catch blocks.

Checklist

  • A comprehensive Linear ticket, providing sufficient context and details to facilitate the review of the PR, is linked to the PR.
  • If my changes require tests, I added them.
  • If my changes affect backward compatibility, it has been discussed.
  • If my changes require an update to the CONTRIBUTING.md guide, I updated it.

Preview

How to QA 1

Run any command with a nonexistent repository name:

prismic webhook list -r nonexistent-repo
# → "Repository not found: nonexistent-repo"

Verify that entity-not-found errors still show specific messages:

prismic webhook disable https://nonexistent-url -r your-repo
# → "Webhook not found: https://nonexistent-url"

Footnotes

  1. Please use these labels when submitting a review:
    ❓ #ask: Ask a question.
    💡 #idea: Suggest an idea.
    ⚠️ #issue: Strongly suggest a change.
    🎉 #nice: Share a compliment.

angeloashmore and others added 3 commits April 11, 2026 00:03
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>
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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}`);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 1770965. Configure here.

@angeloashmore angeloashmore marked this pull request as draft April 11, 2026 00:51
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>
@angeloashmore angeloashmore changed the title fix: show friendly error when repo is not found fix: handle 404 errors with contextual messages Apr 13, 2026
… 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant