Has anyone ever validated 3rd party requests with Zod? Running into an issue where one property might be different down the line since we don't control this api. If I use
safeParse
safeParse
it'll give me an error object but no validated data. Is there a way to retrieve the validated data sans the property that errored out?
Maybe I'm overthinking this?
Solution
you can also do like
const parse = someSchema.safeParse(apiResponse);if (!parse.success) { notifySlackChannel("api response is fucked up", parse.error);}// continue with `apiResponse` and pray nothing breaks
const parse = someSchema.safeParse(apiResponse);if (!parse.success) { notifySlackChannel("api response is fucked up", parse.error);}// continue with `apiResponse` and pray nothing breaks