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