[resolved] tREST component exception handling

One Star

[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

Accepted Solutions
One Star

Re: [resolved] tREST component exception handling

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

All Replies
Community Manager

Re: [resolved] tREST component exception handling

Hi 
You can use tLogCatcher to capture the Java exception and log them into a file or database. 
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] tREST component exception handling

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
Community Manager

Re: [resolved] tREST component exception handling

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
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] tREST component exception handling

Hi Shong,
Thanks again for responding to my question.
Regards
Prem
One Star

Re: [resolved] tREST component exception handling

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