Skip to content

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

Open
@nolimitdev

Description

@nolimitdev

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    supportQuestions, discussions, and general support

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions