简体   繁体   中英

hapi validation for joi and send all error

I am using joi for validating request like

lastName: Joi.string().trim().min(3).optional().error(new Error('Please enter valid name')),

email: Joi.string().email().required().lowercase().error(new Error('Please enter valid Email ID')),

it is working fine and i am also able to send error using failAction but if both validation fails it only send the first failed

like if you enter lastName as h , and email as S@@com so it send only first error ie "Please enter valid name" but I want response containing both error

I also try to use failAction but after failing fist validator it ignore all other validator any suggestion how can i get the required result

set abortEarly: false in server setting by default it is true

server.connection({
    routes: {
        validate: {
            options: {
                abortEarly: false
            }
        }
    }
});

Check here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM