prismicio / prismic-client

The official JavaScript + TypeScript client library for Prismic
https://prismic.io/docs/technical-reference/prismicio-client
Apache License 2.0
168 stars 60 forks source link

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

Closed angeloashmore closed 1 year ago

angeloashmore commented 1 year ago

Types of changes

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:

🦁

codecov-commenter commented 1 year ago

Codecov Report

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

:exclamation: 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%> (ø)