Kurro Lopez · Sep 19

Get HttpStatus in a response using EnsLib.HTTP.OutboundAdapter

Hi community,

I have to do a development that should to connect with a external REST API and it throws different HttpStatus and a body content with the description of the problem.

I'm using the following code:

set tSC = ..Adapter.SendFormDataArray(.tHttpResponse,"POST",tHttpRequest,,,URL)

If the external API responses throws a 400 Status (Bad Request)

the tSC values is an error status and the value of tHttpResponse is empty, so I'm not able to check what is the Status Code and the content.

tSC="0 "_$lb($lb(5002,"<WRITE>zSend+120^%Net.HttpRequest.1",,,,,,,,$lb(,"MYAPP",$lb("$^zSend+120^%Net.HttpRequest.1 +1","$^zSendFormDataArray+64^EnsLib.HTTP.OutboundAdapter.1 +1","$^zCallService+61^MyApp.BO.REST.Base.1 +1","$^zSearch+1^MyApp.BO.REST.Providor.1 +1","$^zMessageHandler+6^MyApp.BO.REST.Providor.1 +1","$^zMessageHeaderHandler+23^MyApp.BO.REST.Providor.1 +1","$^zOnTask+42^Ens.Host.1 +1","D^zStart+62^Ens.Job.1 +2","D^StartEnsembleJob+6^|""%SYS""|STU +1"))))/* ERROR #5002: Error de cache: <WRITE>zSend+120^%Net.HttpRequest.1 */

is there any way to get the HttpStatus of the request?

Best regards,

Product version: IRIS 2021.1
$ZV: IRIS for Windows (x86-64) 2021.1 (Build 215U) Wed Jun 9 2021 09:39:22 ED
0 45
Discussion (2)1
Log in or sign up to continue

I think you get a WRITE error, because it is not really connecting. Does the external REST API receive your request?


Indeed, the problem was caused because the address to which it is going to connect is variable, so the component is not configured with the Server or URL parameters.

I've solved it by the following way:

set ..Adapter.HTTPServer = pRequest.Url
Set URL = pRequest.Url_"/search"
set tHttpResponse = ##class(%Net.HttpResponse).%New()
set tSC = ..Adapter.SendFormDataArray(.tHttpResponse,"POST",tHttpRequest,,,URL)

if $$$ISERR(tSC) && (tHttpResponse="") $$$ThrowStatus(tSC)

// Check what is the status code
set content = ""
while (tHttpResponse.Data.AtEnd = 0) { 
    set content = content_tHttpResponse.Data.Read() 

do pResponse.%JSONImport(content)
set pResponse.StatusCode = tHttpResponse.StatusCode

Kurro Lopez