trigger tDie for ERROR_MESSAGE in tRest

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

Seven Stars JGM
Seven 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

 

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Why Companies Move to the Cloud: 7 Success Stories

Learn how and why companies are moving to the Cloud

Read Now