How do you return an error inside an operation hook?
Use case is sending a push notification after saving a new model instance.
I observe the 'after save'
event, send the push. If this fails for whatever reason, I want to send a 500 response
code. How do I do that?
I am unable to find documentation as to what the ctx
object actually is or contains.
Customer.observe('after save', function(ctx, next) {
//model saved, but sending push failed for whatever reason, and I want to now send a 500 error back to the user
//how? what's inside ctx? how do you send back a response?
next();
});
console.log(ctx)
. It is the context object that represents the request and associated data (ctx.instance
is your Customer instance, for example). To pass errors through operation hooks, pass the error vianext(error);
as the last line in your hook. But that's where my understanding ends—I'm not sure where this ends up or how to handle it in a central place. – Calceiform