Skip to content

Commit

Permalink
fix: throw when given a non-V2 Prismic Rest API in all non-production…
Browse files Browse the repository at this point in the history
… environments (#235)
  • Loading branch information
angeloashmore authored Apr 15, 2022
1 parent 7d3e4c3 commit 0b56b54
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ export class Client {
constructor(repositoryNameOrEndpoint: string, options: ClientConfig = {}) {
if (isRepositoryEndpoint(repositoryNameOrEndpoint)) {
if (
process.env.NODE_ENV === "development" &&
process.env.NODE_ENV !== "production" &&
/\.prismic\.io\/(?!api\/v2\/?)/.test(repositoryNameOrEndpoint)
) {
throw new PrismicError(
Expand Down
17 changes: 17 additions & 0 deletions test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,23 @@ test.serial(
},
);

test.serial(
"constructor throws if a non-V2 Prismic Rest API endpoint is provided",
(t) => {
t.throws(
() => {
prismic.createClient("https://qwerty.cdn.prismic.io/api/v1", {
fetch: sinon.stub(),
});
},
{
instanceOf: prismic.PrismicError,
message: /only supports prismic rest api v2/i,
},
);
},
);

test.serial("constructor throws if fetch is unavailable", (t) => {
const endpoint = prismic.getRepositoryEndpoint("qwerty");

Expand Down

0 comments on commit 0b56b54

Please sign in to comment.