allcount / allcountjs

Rapid application development framework for Node.js
http://allcountjs.com
MIT License
403 stars 88 forks source link

How to add extra validation on hook #115

Closed ghost closed 8 years ago

ghost commented 8 years ago

Is it possible to add extra validation inside a hook? i.e.:

      beforeSave: function (Entity) {
         if (Entity.someValue > 10000) {
            throw new Exception("someValue is wrong"); 
         }
      }

I've also tried to return a rejected Promise, as the docs says, but I can't prevent saving.

paveltiunov commented 8 years ago

@IGZgustavomarin you can add ValidationError dependency and throw it as follows: throw new ValidationError({field: "field error message"})