const { z } = require('zod')
const getUserById = async () => {
// Not found
throw new Error('400')
}
const IdToUser = await z
.string()
.transform(async (id) => {
return await getUserById(id)
.catch(e => {
console.log('Who would have guessed this person could not be found')
// zod say you can't throw an error in a transform
return null
})
})
.refine(v => v, {
message: 'See that transform above, must be that getUserById did not find our user',
})
.parseAsync('foo')
.catch(e => console.log(e.issues))