Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Streamlining user types in Qlik Cloud capacity-based subscriptions: Read the Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[resolved] tREST component exception handling

Hi,
I am trying to use tREST component to call a Rest api service.  For some calls I am getting expected results.
For some calls error_code (for eg 400) is returned with body as null. 
How do I handle or retrieve the exact error message whenever there is a webexception or any other exceptions.
Thanks
Labels (3)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Just an update on this topic.
I  modified the tREST_begin.javajet file to retrieve the error message using the errorResponse_<%=cid%>.getEntityInputStream() and was able to retrieve the exact error message from the rest API service i was calling.
Thanks 
Prem

View solution in original post

5 Replies
Anonymous
Not applicable
Author

Hi 
You can use tLogCatcher to capture the Java exception and log them into a file or database. 
Best regards
Shong
Anonymous
Not applicable
Author

Shong,
Thank you for taking time to respond to my question.
When I look at the java code generated by trest component it is handling only UniformInterfaceException as shown below and not webexception. Is there way to update the java code to handle additional exceptions. If not, how can i use custom java class/code to call the rest api and handle the webexception. ( I am new to Talend and have very basic java knowledge )
In my case the service returns error message when i call via postman but returns error code 400 in talend.
Is there a way to retrieve the webexception error message when the error code is 400.
try 
{
post method.... 

catch (com.sun.jersey.api.client.UniformInterfaceException ue) {
                                   errorResponse_tREST_2 = ue.getResponse();
              }
// for output
row5 = new row5Struct();
if (errorResponse_tREST_2 != null) {
row5.ERROR_CODE = errorResponse_tREST_2.getStatus();
} else {
row5.Body = restResponse_tREST_2;
}
Thanks 
Prem
Anonymous
Not applicable
Author

Hi 
tLogcatcher is used to capture the Java exception during the job execution, it can not capture the webexception like http 400 error code however, the error code is still output on the console, as a workaround, you can use tRedirectOuput component to redirect the error code with execution time to a log file, refer to this topic:
https://www.talendforge.org/forum/viewtopic.php?pid=108102
BR
Shong
Anonymous
Not applicable
Author

Hi Shong,
Thanks again for responding to my question.
Regards
Prem
Anonymous
Not applicable
Author

Just an update on this topic.
I  modified the tREST_begin.javajet file to retrieve the error message using the errorResponse_<%=cid%>.getEntityInputStream() and was able to retrieve the exact error message from the rest API service i was calling.
Thanks 
Prem