Skip to content

chain handler docs are wrong #103

@westandy-dcp

Description

@westandy-dcp

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions