As of April 12th, you must go to Progress SupportLink to create new support cases or to access existing cases. Please, bookmark the SupportLink URL and use the new portal to contact the support team.
Timeout when try to throw custom error inside findAsync
Y
Yegor Kozlov
started a topic
almost 7 years ago
Hello,
I noticed not usual behavior for throwing an error inside then handler of findAsync. Here is the test code that I used in custom endpoint
function onRequest(request, response, modules) { var collectionAccess = modules.collectionAccess;
collectionAccess.collection('Collection').findAsync({}) .then(function(entities) { if(entities.length > 0) { return response.error('Count is more than 0'); } return response.complete(200) }); }
The problem is that I have a timeout exception here. My 'Collection' isn't empty. It's only for promise-based functions. For non promise-based function I received an error as expected
function onRequest(request, response, modules) { var collectionAccess = modules.collectionAccess;
collectionAccess.collection('Collection').find({},function(entities) { if(entities.length > 0) { return response.error('Count is more than 0'); } return response.complete(200) }); }
And now I'm afraid to use promise-based collection functions because of possible timeouts.
Regards, Yegor
Best Answer
A
Austin Moothart
said
almost 7 years ago
The issue here is that the response.error call needs to be wrapped with setImmediate. For example:
This should solve your problem today. We're enhancing Business Logic to do this automatically so in the future you can write the code as you originally did.
This should solve your problem today. We're enhancing Business Logic to do this automatically so in the future you can write the code as you originally did.
Y
Yegor Kozlov
said
almost 7 years ago
Thanks Austin, with catch and setImmediate it works
Yegor Kozlov
Hello,
I noticed not usual behavior for throwing an error inside then handler of findAsync.
Here is the test code that I used in custom endpoint
The problem is that I have a timeout exception here. My 'Collection' isn't empty. It's only for promise-based functions.
For non promise-based function I received an error as expected
And now I'm afraid to use promise-based collection functions because of possible timeouts.
Regards, Yegor
The issue here is that the response.error call needs to be wrapped with setImmediate. For example:
This should solve your problem today. We're enhancing Business Logic to do this automatically so in the future you can write the code as you originally did.
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstWani
Hi Yegor,
I tried the same code for findAsync and I got 504 Gateway timeout error.
When I tried the sample code from documentation - http://devcenter.kinvey.com/rest/reference/business-logic/reference.html#collection-access-module, the following code worked correctly for me:
Can you try out this code and tell me if this works for you?
Regards,
Wani
Kinvey Support
Yegor Kozlov
Hi Wani,
Thanks for your reply.
This code works but it's not my case, I don't have an error in query.
I want to throw my custom error(call response.error) inside success result.
It seems like it doesn't work only for endpoints, with hooks everything seems fine here.
Wani
Hi,
If you modify the code I supplied like below, that should work for you.
Let me know if that helps.
Regards,
Wani
Yegor Kozlov
Still get timeouts with your variant of code...
Wani
Can you share the app key (kid_xxx) and endpoint name?
Regards,
Wani
Austin Moothart
The issue here is that the response.error call needs to be wrapped with setImmediate. For example:
This should solve your problem today. We're enhancing Business Logic to do this automatically so in the future you can write the code as you originally did.
Yegor Kozlov
Thanks Austin,
with catch and setImmediate it works
-
How do I access query string values for GET and DELETE requests?
-
Basic Authentication in Business Logic
-
How do I cascade delete entities from related collections?
-
All BL failing with Violation Error
-
How do I send push notifications?
-
Whenever I try to query by _id, I get zero results
-
receiving SOCKETTIMEDOUT when requesting external http response
-
Unique Constraints on a collection column?
-
Need some help with grouping
-
Accessing Endpoint from Collection Hook
See all 342 topics