Five Stars

trigger tDie for ERROR_MESSAGE in tRest

Could you guys help me understand how do I abort my job when tRest return an error.  I tried doing Run IF -->tDie directly from tRest 

((String)globalMap.get("tREST_1_ERROR_MESSAGE")).length() >0

but that results in NPE 

Error on line 1 of document  : Premature end of file. Nested exception: Premature end of file.
Exception in component tREST_1
java.lang.NullPointerException

So now I'm using tMap to separate Body from ERROR_MESSAGE. I can't figure out what to do with error row though. I can't use "Run If" trigger directly with tMap:

2017-10-03_2134.png

 

What is the typical way of handling error from REST call?

 

Thanks,

Dima

Tags (3)
3 REPLIES
Six Stars JGM
Six Stars

Re: trigger tDie for ERROR_MESSAGE in tRest

There's a few ways to do what you want. The reason you're getting a NPE is because Talend will evaluate the "if" links when the component they are attached to runs their "end" section -- since the subjob with your tREST component has not even initialized at this point, the globalMap key will not be populated and the get will return null. 

 

Here's a quick example of two ways to do what you want:

1) use onSubJobError off the tREST subjob 

or

2) use a stub component to ensure the tREST subjob is complete before evaluating your if statement

 

image.png

 

Five Stars

Re: trigger tDie for ERROR_MESSAGE in tRest

I tried doing a OnSubjobError but tDie is not triggered. I can catch ERROR_CODE though

2017-10-04_0035.png

Here's my tMap just in case

2017-10-04_0038.png

Five Stars

Re: trigger tDie for ERROR_MESSAGE in tRest

I tried using another approach suggested with tJava component but it fails with error:

tJava_1 null