Skip to content

Commit 517471a

Browse files
authored
chore: include original value in zod error message (#257)
1 parent 0bc8cb9 commit 517471a

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@vesselapi/integrations",
3-
"version": "1.0.41",
3+
"version": "1.0.42",
44
"description": "Vessel integrations",
55
"main": "dist/index.js",
66
"module": "dist/index.mjs",

src/sdk/client.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ export const formatUrl = (
5757
: (url as `${HttpsUrl}/${string}`);
5858
};
5959

60+
const customErrorMap: z.ZodErrorMap = (_, ctx) => {
61+
return {
62+
message: `${ctx.defaultError}. Received value: ${ctx.data}`,
63+
};
64+
};
65+
6066
export const toBase64 = (str: string) => Buffer.from(str).toString('base64');
6167

6268
const _requestWithAxios = async ({
@@ -219,7 +225,9 @@ export const makeRequestFactory = (
219225
});
220226
}
221227

222-
const zodResult = await response.options.schema.safeParseAsync(body);
228+
const zodResult = await response.options.schema.safeParseAsync(body, {
229+
errorMap: customErrorMap,
230+
});
223231
if (!zodResult.success) {
224232
if (options.strict) {
225233
throw new IntegrationError('Validation failed on client response', {

0 commit comments

Comments
 (0)