Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ module.exports = function(options, key, validations, param) {
else if (_.isFunction(validations)) {
try {
const test = validations(param);
if (!_.isBoolean(test)) {
return { error: 'The validation response must be boolean.' };
// If the custom test returns a string, use that as the error message
if (_.isString(test)) {
return { error: test };
}
else if (!_.isBoolean(test)) {
return { error: 'The validation response must be boolean or an error message.' };
}
return test ? { value: param } : { error: 'The validation failed' };
} catch (e) {
Expand Down