cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Getting the Status from a REST call

TimBurns
New Contributor III

Hi Folks,
Iโ€™m having trouble getting a proper handling from Snaplogic on a REST call.

So the rest call will return on success:
โ€œentityโ€:
{
โ€œMessageIdโ€:โ€œ0101017165ec422f-dfa2bb38-faac-4c48-bcd7-0e2869d80fb6-000000โ€, โ€ฆ}

And on Error:

โ€œentityโ€: "ERROR: An error occurred โ€ฆ

Thing is these are different - one is a dictionary and the other a string. So it fails badly when I check for entity error.

Is there a standard pattern for this?

Thanks,
Tim

image

1 ACCEPTED SOLUTION

tstack
Former Employee

Another option is to use the matches operator that can check a value against a pattern. The nice thing about this approach is that the pattern looks roughly like the value being matched and the type of the value is implicitly checked. So, an error wonโ€™t be raised if the value has an unexpected type.

For your first example:

The object pattern, { MessageId }, would only match objects that contain the property MessageId. The full expression would look like this:

$entity matches { MessageId }

For the second example:

A string pattern that uses the ... wildcard can check for a value with a prefix. The full expression would look like:

$entity matches "ERROR:"...

(Unfortunately, while there is documentation for the match operator, the documentation for matches seems to be missing at the moment. Weโ€™ll get that fixed)

View solution in original post

4 REPLIES 4

TimBurns
New Contributor III

This is what I have: $entity.toString().contains(โ€œERRORโ€)

Anil
New Contributor III

Hi @TimBurns

The expression the router snap should look like this.

$entity instanceof Object

image

Regards
Anil Kumar

tstack
Former Employee

Another option is to use the matches operator that can check a value against a pattern. The nice thing about this approach is that the pattern looks roughly like the value being matched and the type of the value is implicitly checked. So, an error wonโ€™t be raised if the value has an unexpected type.

For your first example:

The object pattern, { MessageId }, would only match objects that contain the property MessageId. The full expression would look like this:

$entity matches { MessageId }

For the second example:

A string pattern that uses the ... wildcard can check for a value with a prefix. The full expression would look like:

$entity matches "ERROR:"...

(Unfortunately, while there is documentation for the match operator, the documentation for matches seems to be missing at the moment. Weโ€™ll get that fixed)

TimBurns
New Contributor III

Thank you. That is cleaner.

$entity instanceof Object && โ€œMessageIdโ€ in $entity

This is what I doing before and it was kind of icky.