Solved

httpGet Operation - behaviour on HTTP Status 4040 ?

  • 21 May 2024
  • 5 replies
  • 48 views

Userlevel 5
Badge +1

(Title should read 404 not 4040)

 

Hi

If I use <arc:call op="httpGet" in="http"> , will a 404 response raise an exception which I need to catch or can I check the http:statuscode ?

icon

Best answer by James B 23 May 2024, 22:01

View original

5 replies

Userlevel 3

Hi Russel, 

 

Do you mean you want to capture the server response code? Could you please elaborate a bit more to help us understand the issue? A 404 error usually indicates that the server cannot find the web page requested by the user.

 

 

 

 

 

Userlevel 5
Badge +1

Hi

 

The API endpoint I am calling uses 404 to indicate a record has not been found and returns

{"message":"No orders found"}

as the body. which fairly common practice for accessing data resources.

I have managed to use try/catch around my httpGet and it successfully catches the 404, but cannot read http:content

Looks like I will just have to assume that 404 means “No orders found”

 

Userlevel 3

Hi Russel,

 

Did you try accessing it using response http:content attribute?

<arc:set attr="http.URL" value="https://SomeURL" />
<arc:set attr="http.user" value="user" />
<arc:set attr="http.password" value="password" />
<arc:call op="httpGet" in="http" out="response">
<arc:set attr="output.data" value="[response.http:content]" />
</arc:call>

<arc:set attr="output.filename" value="httpResponseContent.txt" />
<arc:push item="output" />

In the above sample script, the response from the API will be saved in output file.

Do you see any error?

Userlevel 5
Badge +1

I did, but when the status is 404 Cdata Arc didn’t populate content

Userlevel 6
Badge

In ArcScript, the body of the HTTP error is not returned with the exception code, but you can see the response error if you enable the logging for the connector:

 

<!-- read this log after the fact -->
<arc:set attr="http.logfile" value="/somepath/HTTPLog.txt" />
<arc:set attr="http.verbosity" value="3" />

<arc:set attr="http.URL" value="https://SomeURL" />
<arc:set attr="http.user" value="user" />
<arc:set attr="http.password" value="password" />
<arc:call op="httpGet" in="http" out="response">
<arc:set attr="output.data" value="[response.http:content]" />
</arc:call>

<arc:set attr="output.filename" value="httpResponseContent.txt" />
<arc:push item="output" />

 

But there is not a real time examination of the HTTP body of a 4xx error in the exception thrown. 

The REST connector is a better way in the flow to manage endpoints that return a body that you need to examine - in the Advanced tab, you will find an option to create output messages for errors so you can act according to the body of the error reply:

 

 

Reply