|
1 | 1 | import * as z from "./z"; |
2 | 2 | import { openapiSpec } from "./openapiSpec"; |
3 | 3 | import type { OpenAPIObject } from "zod-openapi/lib-types/openapi3-ts/dist/oas31"; |
| 4 | +import { fromZodError } from "zod-validation-error/v3"; |
4 | 5 | import coerceParams from "./coerceParams"; |
5 | 6 | export { openapiSpec }; |
6 | 7 | export { type SelectTree, parseSelect } from "./parseSelect"; |
@@ -778,20 +779,27 @@ export class Stl<Plugins extends AnyPlugins> { |
778 | 779 | context.endpoint[coercedQuery] ??= coerceParams(context.endpoint.query); |
779 | 780 | context.parsedParams.query = await context.endpoint[coercedQuery] |
780 | 781 | .parseAsync(params.query, parseParams) |
781 | | - .catch(prependZodPath("<stainless request query>")); |
| 782 | + .catch(prependZodPath("<query>")); |
782 | 783 | } |
783 | 784 | if (context.endpoint.path) { |
784 | 785 | context.endpoint[coercedPath] ??= coerceParams(context.endpoint.path); |
785 | 786 | context.parsedParams.path = await context.endpoint[coercedPath] |
786 | 787 | .parseAsync(params.path, parseParams) |
787 | | - .catch(prependZodPath("<stainless request path>")); |
| 788 | + .catch(prependZodPath("<path>")); |
788 | 789 | } |
789 | 790 | context.parsedParams.body = await context.endpoint.body |
790 | 791 | ?.parseAsync(params.body, parseParams) |
791 | | - .catch(prependZodPath("<stainless request body>")); |
| 792 | + .catch(prependZodPath("<body>")); |
792 | 793 | } catch (error) { |
793 | 794 | if (error instanceof z.ZodError) { |
794 | | - throw new BadRequestError({ issues: error.issues }); |
| 795 | + let validationError = fromZodError(error).message; |
| 796 | + if (validationError.startsWith("Validation error: ")) { |
| 797 | + validationError = validationError.slice("Validation error: ".length); |
| 798 | + } |
| 799 | + throw new BadRequestError({ |
| 800 | + message: validationError, |
| 801 | + issues: error.issues, |
| 802 | + }); |
795 | 803 | } |
796 | 804 | throw error; |
797 | 805 | } |
|
0 commit comments