validate: { params: joi.object({ itemCode: joi.string().required() }), payload: joi.object({ A: joi.number().required().valid(1, 2, 3, 4).error( new Error('Error 1')), B: joi.string().required().max(990).error( new Error('Error 2')) }), failAction: async (request, h, err) => { const { itemCode } = request.params const { server } = request const A = request.payload.A const B = request.payload.B return createView(server, code, h, A, B, err) } } } }] So when my payload on a POST gets validated by joi i need it so both custom errors will come through in the err in the scenario that they are both erroring, at the moment if the first one errors it will only take 'Error1' through as it jumps out of the code as soon as it fails the validation. I looked on the joi documentation and it said in your server make sure abort Early is set to default for it to continue on and it is (see below), and this does work but only if i take away the custom error messages, if i add them back in Im back to square one. I just cant figure out how to take both custom errors across.async function createServer () { // Create the hapi server const server = hapi.server({ port: config.port, routes: { auth: { mode: 'try' }, validate: { options: { abortEarly: false } } }, cache: cache })
Submitted November 11, 2019 at 07:17PM by dizzyack
No comments:
Post a Comment