Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: throw NotFoundError when a document cannot be found #316

Merged
merged 1 commit into from
Aug 11, 2023

Conversation

angeloashmore
Copy link
Member

Types of changes

  • Chore (a non-breaking change which is related to package maintenance)
  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

This PR fixes getFirst() and all dependent methods, including getByUID() and getByID(), by throwing a NotFoundError when a matching document is not found.

NotFoundError is a subclass of PrismicError, retaining compatibility with instanceof PrismicError.

Before:

import { createClient } from "@prismicio/client";

const client = createClient("example-prismic-repo");
await client.getByUID("page", "non-existent");
// => throws PrismicError

After:

import { createClient } from "@prismicio/client";

const client = createClient("example-prismic-repo");
await client.getByUID("page", "non-existent");
// => throws NotFoundError

Checklist:

  • My change requires an update to the official documentation.
  • All TSDoc comments are up-to-date and new ones have been added where necessary.
  • All new and existing tests are passing.

🦁

@codecov-commenter
Copy link

Codecov Report

Merging #316 (e002238) into master (76fa2ca) will not change coverage.
The diff coverage is 100.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@           Coverage Diff           @@
##           master     #316   +/-   ##
=======================================
  Coverage   99.96%   99.96%           
=======================================
  Files          50       50           
  Lines        6045     6045           
  Branches      294      294           
=======================================
  Hits         6043     6043           
  Misses          2        2           
Files Changed Coverage Δ
src/createClient.ts 100.00% <100.00%> (ø)

Copy link
Member

@lihbr lihbr left a comment

Choose a reason for hiding this comment

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

LGTM :) Easy one!

@angeloashmore angeloashmore merged commit 74fce89 into master Aug 11, 2023
12 checks passed
@angeloashmore angeloashmore deleted the aa/not-found-error-on-get-first branch August 11, 2023 21:38
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.

3 participants