Skip to content
This repository was archived by the owner on Dec 12, 2021. It is now read-only.
This repository was archived by the owner on Dec 12, 2021. It is now read-only.

Promise chain friendly errors #51

@xpepermint

Description

@xpepermint

Hi. I started using promises all over my code because it makes the code look beautiful. I really like this library but the problem is that errors are returned as Object not as instanceof some ValidationError class.

What I would propose is to wrap errors into validate.ValidationError class where you can still get an object calling toObject() method thus everything works the same way we just add a better support for promises.

Example:

  validate.async(req.body, contraints).then(function() {
    return Model.save(req.body);
  }).then(function(result) {
    res.status(201).json(result);
  }).catch(validate.ValidationError, function(err) {
    res.status(422).json(err);
  }).catch(function(err) {
    res.status(500).json(err);
  });

I would appreciate if we can do this small update. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions