Skip to content

Commit

Permalink
Fix withValidation example
Browse files Browse the repository at this point in the history
  • Loading branch information
mpppk committed Dec 14, 2024
1 parent b63eb5c commit 9cde0a4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
13 changes: 8 additions & 5 deletions pkgs/examples/simple/withValidation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { newZodValidator, ZodApiEndpoints } from "@notainc/typed-api-spec/zod";
import { ValidateError, withValidation } from "@notainc/typed-api-spec/fetch";
import { z, ZodError } from "zod";
import { withValidation } from "@notainc/typed-api-spec/fetch";
import { z } from "zod";
import { SpecValidatorError } from "@notainc/typed-api-spec/fetch";

const GITHUB_API_ORIGIN = "https://api.github.com";

Expand Down Expand Up @@ -47,9 +48,11 @@ const main = async () => {
`${GITHUB_API_ORIGIN}/repos/nota/typed-api-spec/topics?page=1`,
{ headers: { Accept: "application/vnd.github+json" } },
);
} catch (e: unknown) {
if (e instanceof ValidateError) {
console.log("error thrown", (e.error as ZodError).format());
} catch (e) {
if (e instanceof SpecValidatorError) {
console.log("error thrown", e.error);
} else {
throw e;
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions pkgs/typed-api-spec/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ export * from "./query-string";
export * from "./spec";
export * from "./type";
export * from "./url";
export * from "./validator/validate";
export * from "./validator/request";
export * from "./validator/response";
6 changes: 3 additions & 3 deletions pkgs/typed-api-spec/src/fetch/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import {
AnySpecValidator,
RequestSpecValidatorGenerator,
runSpecValidator,
} from "../core/validator/request";
} from "../core";
import {
AnyResponseSpecValidator,
ResponseSpecValidatorGenerator,
runResponseSpecValidator,
} from "../core/validator/response";
import { ValidatorInputError } from "../core/validator/validate";
} from "../core";
import { ValidatorInputError } from "../core";

const dummyHost = "https://example.com";

Expand Down

0 comments on commit 9cde0a4

Please sign in to comment.