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

optional param in schema cause error : Cannot set property 'message' of undefined (v4.1) #398

Closed
vitaliybilous opened this issue Aug 30, 2017 · 3 comments
Labels

Comments

@vitaliybilous
Copy link

lib : 4.1,
node : 8.1.4,
os : ubuntu 14.04

Use legacy API (schema) for validation.
My code:

export const validatePostPageData = async (req, res, next) => {
  /*
  POST data : { data : { props : "ABC" } }
  */
  req.checkBody({
    'data.props' : {
      optional: true
    }
  });

  const result = await req.getValidationResult();

  if (!result.isEmpty()) {
    res.status(400).send({error: result.array().map(({param, msg}) => ({param, msg}))});
    return;
  }

  next();
};

Displayed error in console:
UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot set property 'message' of undefined

If remove the optional rule and add other - all work fine

@gustavohenke
Copy link
Member

Thanks for the report. This is indeed a bug when using schema validation + optional as the first found key in a parameter object.

@gustavohenke
Copy link
Member

Fix published in v4.1.1.

@lock
Copy link

lock bot commented Jun 1, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants