I have these two function implementations that wrap httpGet(Map params, Closure closure)
and httpPost(Map params, Closure closure)
.
In both cases, the debug logs of the responses contain the expected data. Returning that data in the httpGet case behaves correctly, but with httpPost it is returned as null. The alternate flavor does not have this issue: httpPost(String uri, String body, Closure closure)
I can work around this by assigning the response to some other global variable and passing it back that way, but I'd appreciate any ideas on what is causing this to not work directly. It's not an issue with the specific response data- returning anything from inside the closure fails, even plain old data.
def httpGetExec(params, throwToCaller = false)
{
logDebug("httpGetExec(${params})")
try
{
httpGet(params)
{ resp ->
if (resp.data)
{
logDebug("resp.data = ${resp.data}")
return resp.data
}
}
}
catch (Exception e)
{
logDebug("httpGetExec() failed: ${e.message}")
if(throwToCaller)
{
throw(e)
}
}
}
def httpPostExec(params, throwToCaller = false)
{
logDebug("httpPostExec(${params})")
try
{
httpPost(params)
{ resp ->
if (resp.data)
{
logDebug("resp.data = ${resp.data}")
return resp.data
}
}
}
catch (Exception e)
{
logDebug("httpPostExec() failed: ${e.message}")
if(throwToCaller)
{
throw(e)
}
}
}