Repository navigation
Replies: 1 comment
|
The reason The rejection comes from inside your morph function, so that's where the message has to be set, via the same options object const stringToObjectId = type('string>0').pipe.try((input, ctx) => {
if (input.length < 24) {
return ctx.reject({ message: 'Invalid order id' })
}
// ...
})That hardcodes the message into the type itself though, and it sounds like you actually want different messages depending on where const objectId = (message = 'Invalid ObjectId') =>
type('string>0').pipe.try((input, ctx) =>
input.length < 24 ? ctx.reject({ message }) : input
)
const schema_in = type({
order_id: objectId('Invalid order id'),
})Same runtime behavior, but now the message is parameterized at the point where you actually know what a good message is, instead of trying to override it after the fact from outside the pipe. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I have the following custom type that raises an error:
I then use that type:
How do I get the error message "Invalid order id" to show when any error happens inside of the .pipe() ?
All reactions