for the beforeCreate method, in your example you said to use callback(err) for errors and callback(null, newResource) for successes. However, this is completely wrong as far as I can tell. I had to do the following:
const chainHandler = new jag.ChainHandler();
chainHandler.beforeCreate = (request, newResource, callback) => {
if ( somethingIsWrong) {
const error = { status: ###, code: 'ALLBAD', title: 'Describe the issue'};
callback(error);
} else {
const updatedId = {...newResource, id: uuid()};
callback(null, updatedId, updatedId);
}
}
For the error callback, if you do not have an object with those specific properties, then the response will return error [{}] which is not helpful.
For the success callback, if you do not specify the third argument, you get callback is not a function on line 262 in sqlHandler for jsonapi-store-relationaldb.
If you put request in the 2nd argument, then you get a Circular Reference error from an JSON.stringify(argsOut) from the handlerEnforcer line 32 in this framework.
I hope this saves you some time. This was very confusing to figure out.
for the
beforeCreatemethod, in your example you said to usecallback(err)for errors andcallback(null, newResource)for successes. However, this is completely wrong as far as I can tell. I had to do the following:For the
errorcallback, if you do not have an object with those specific properties, then the response will return error[{}]which is not helpful.For the
successcallback, if you do not specify the third argument, you getcallback is not a functionon line 262 insqlHandlerforjsonapi-store-relationaldb.If you put
requestin the 2nd argument, then you get aCircular Referenceerror from anJSON.stringify(argsOut)from thehandlerEnforcerline 32 in this framework.I hope this saves you some time. This was very confusing to figure out.