2

I need to make custom validation of instance before saving it to MySQL DB. So I perform (async) check inside beforeValidate model hook.

MyModel.beforeValidate = function(next){
  // async check that finally calls next() or next(new Error('fail'))
}

But when check fails and I pass Error obj to next function, the execution continues anyway. Is there any way to stop execution and response to client with error?

IvanZh
  • 2,265
  • 1
  • 18
  • 26

1 Answers1

2

This is a known bug in the framework, see https://github.com/strongloop/loopback/issues/614

I am working on a new hook implementation that will not have issues like the one you have experienced, see loopback-datasource-juggler#367 and the pull request loopback-datasource-juggler#403

Miroslav Bajtoš
  • 10,667
  • 1
  • 41
  • 99
  • Thanks for your work! Attaching link to the more complete description https://gist.github.com/bajtos/b8157112452eeaf984c9#file-new-hooks-docs-md – IvanZh Jan 31 '15 at 13:14