Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X
A service is unable to execute completely because the script time configured is less.
Written code in catch block of the service.But code in catch block is not executing.
Let me know How do I capture Script timeout error in catch block
You can use script log statements(like logger.warn("message") )in the catch block code, then check the log file to know where is the service performed.
Have performed what you suggested.
But No luck,It is not showing log statements written in Catch block in Script log.
I see Script timeout error log for this service in Application Log.
But unable to capture it in catch block.
Which statement do you use? How about using logger.error("message")? Can you be sure the service has been executed in that step?
I suggest you can set more statements in different code areas.
Yes I am sure ,the service got executed.
We are performing for loop 5000 times.
I can see the count till 1700 using logger.warn statements in try block.
After that it is not able to go further due to script timeout and I tried logger.error("Message") in catch block.But No luck
I got your point, let me check if we can catch timeout in JS script, then go back to you.
JS provides two fields on the err that is caught --- err.name and err.message.
you can try below:
try{
//service code
} catch (err){
if(err.message.indexOf("Timeout") > 0){// do something to address the timeout exception}
}
Other related information you can refer article CS252885
var a;
try{
for(var i=0;i<10000000000000;i++)
{
a = 5;
}
result = a;
}
catch(err)
{
if(err.message.indexOf("Timeout") > 0){
logger.error("Timeout");
me.Status = "Failed";
}
}
The above code runs more than configured script time.But it is not showing Timeout(Check logger statement above) in logs and it doesn't make Status property as Failed.
But it shows general script timeout error as "Execution of Script terminated after : 30 seconds. Timeout configured for 30 seconds."
Please try the same code from your end and let me know.I am using ThingWorx 8.5.0-b12
After further testing and investigation in my environment, seems it isn't possible to handle ScriptTimeoutException from Script Service, you can refer CS341183 . Because ScriptTimeoutException cannot bubble up from backend code to composer code for third-party limitation.
Could you let me know if there is any workaround to handle this?
How about designing the execution logic of the service to fulfill a same business requirement?
For example, at the beginning of the service, set me.status = pending and output message "start executing the service"; At the last of the service, set me.status=success. If the service is not executed successfully and timeout, then me.status will keep pending value.
Just checked it with basic service I wrote above.It works great!!
Will apply the same with real business logic and Let you know.
Thanks!!