Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chain handler docs are wrong #103

Open
westandy-dcp opened this issue Aug 21, 2019 · 0 comments
Open

chain handler docs are wrong #103

westandy-dcp opened this issue Aug 21, 2019 · 0 comments

Comments

@westandy-dcp
Copy link

westandy-dcp commented Aug 21, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant