Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set both custom error code and custom message inside custom function #3059

Open
nolimitdev opened this issue Dec 30, 2024 · 0 comments
Open
Labels
support Questions, discussions, and general support

Comments

@nolimitdev
Copy link

Runtime

n/a

Runtime version

n/a

Module version

n/a

Used with

No response

Any other relevant information

No response

How can we help?

const myCustomFn = (value, helpers) => {
    // If condition is matched I want to set both code 'my.error.code' and message inside this myCustomFn
    // but helpers.error() does not allow setting message and helpers.message() does not allow setting code other then "custom"
    // and I do not want in many places in code use .custom() with combination .messages() because messages will be repetitive:
    // .custom(myCustomFn).messages({ 'my.error.code' : 'My error message' })
    // I tried to use helpers.prefs.messages['my.error.code'] = 'My error message' but it causes error
    if (.........)
        return helpers.error('my.error.code');

    return value;
};

joi.object({
.........
})
.xor(.......)
.custom(myCustomFn)
@nolimitdev nolimitdev added the support Questions, discussions, and general support label Dec 30, 2024
@nolimitdev nolimitdev changed the title Set both custom error code and custom message using custom() at once Set both custom error code and custom message inside custom function Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support Questions, discussions, and general support
Projects
None yet
Development

No branches or pull requests

1 participant