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

failover() support for default on errors #1535

Closed
WesTyler opened this issue Jun 28, 2018 · 5 comments
Closed

failover() support for default on errors #1535

WesTyler opened this issue Jun 28, 2018 · 5 comments
Assignees
Labels
feature New functionality or improvement
Milestone

Comments

@WesTyler
Copy link
Contributor

WesTyler commented Jun 28, 2018

Describe the problem you are trying to fix (provide as much context as possible)

From the discussion here:
per @genediazjr

I'm thinking of an API for Joi that would allow a default value similar to any.default() but only if the original value is invalid. The value key on the error object will contain the set infInvalid value instead of the original value. Or we can put it on separate key whichever would be better.

Which API (or modification of the current API) do you suggest to solve that problem ?

I would like to propose adding an optional config param to .default():

Joi.string().default('name', { invalid: true })

Are you ready to work on a pull request if your suggestion is accepted ?

Yes.

@WesTyler
Copy link
Contributor Author

@Marsup I see that you added this to the Priorities project. If you're open to this addition, I can go ahead and work on it.

@Marsup
Copy link
Collaborator

Marsup commented Jul 12, 2018

It's a P3 but sure. Remember there's already a 2nd argument for default.
Also should default apply to invalid, undefined values, or both ? This API seems confusing to me.

@WesTyler
Copy link
Contributor Author

WesTyler commented Jul 12, 2018

Remember there's already a 2nd argument for default

👍

should default apply to invalid, undefined values, or both

My thought was apply only to empty/undefined values as it currently does, unless you have set the invalid: true option in which case it will apply on empty/undefined as well as invalid.

@Marsup
Copy link
Collaborator

Marsup commented Jul 12, 2018

What if you only want invalid ?

@WesTyler
Copy link
Contributor Author

I guess that's something we need to decide on, then. My understanding of the original request was "invalid in addition to empty".

So if we need to consider "empty", "invalid", and "empty or invalid" as individual use cases then yeah this is a bit confusing.

@hueniverse hueniverse changed the title Discussion - use .default() value on invalid in addition to empty values. failover() support for default on errors Jun 2, 2019
@hueniverse hueniverse added feature New functionality or improvement and removed request labels Jun 2, 2019
@hueniverse hueniverse self-assigned this Jun 2, 2019
@hueniverse hueniverse added this to the 16.0.0 milestone Jun 2, 2019
@hueniverse hueniverse added the v16 label Aug 10, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Feb 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New functionality or improvement
Projects
None yet
Development

No branches or pull requests

3 participants