Start a new topic

response.continue does not seem to work according to the description

Hello,


According to the BL reference, response.continue is “a function that indicates the business logic is complete and that normal request processing should continue”. However, that is not what we see. In the preSave hook, there is a check if body._id is undefined to see if the object has already been saved or not. If it is NOT undefined (the object has been already saved),  response.continue() is called. 


However, it seems to be ignored and the BL script continues to run to

 completion. My understanding that it should skip the rest of the BL script and just execute the regular save. But that’s not what we see. 


When we tried calling return response.continue() instead of just response.continue(), it became erratic and preFetch and postFetch were called even though it is a save operation, not a query.


Thanks

Mark

 


Hi Mark,


Can you share the preSave hook code? Can you also explain what it is supposed to do in brief?


Also, you are checking value of body._id to differentiate between a POST and a PUT request. Is that right?



Regards,

Wani

Kinvey Support

Hi Wani,


Yes, I can share the preSave hook code via some other means than the forum. The preSave hook checks for the availability of a resource related to the entity being saved, than creates the related object and stores it in the temporary object store to be saved in the postSave hook. 


Yes, we can say that the value of body._id is checked to differentiate between a POST and a PUT request. The related entity needs to be saved only once when the main entity is saved for the first time. That's the reason the response.continue is used after the first save to bypass the BL and just save the main entity (it is actually a tree).


Also, we continue to see prefFetch/postFetch being called with and empty query for both save and retrieve operations. For retrieve, I see both the good call with the right query and the bad call with the empty "{}" query.


Thanks

Mark

Hi Mark,


Would it be possible for you to share the BL code snippet instead of the complete code after removing any code that might be confidential? I am interested in looking at the way you have structured the conditions and response.continue() statements.



Thanks,

Wani

Hi Wani,


Here is the sniper you requested from the preSave hook:


if (request.body._id === undefined)

{

  logger.info('request.body._id === undefined');

}

else

{

  alreadySaved = true;

  response.continue();

}


The 'alreadySaved' flag is a temporary workaround to fix this problem and will be removed once we get response.continue() to work properly.


Thanks

Mark


Login or Signup to post a comment