Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

getBody() of RESTResponseV2 always return null if have error

ducdhm
Giga Contributor

Hey guys,

I'm developing an application which interacts a lot with REST. In some case, the error will be occurred such as Authorization header is error and I want to get the response body for debugging. With previous version of RESTResponse, I can do log the response body but in V2, the body always is null if haveError() is true. Is there any work around for this?

Cheers,

Duc

1 ACCEPTED SOLUTION

ducdhm
Giga Contributor

Seems like SNC changed in getBody() method of RESTResponseV2. Now I can get the body even haveError() is true


View solution in original post

9 REPLIES 9

tony_barratt
ServiceNow Employee
ServiceNow Employee

Hi Duc,



Thanks for that. I see now that this is the relevant wiki article:


RESTMessageV2 API - ServiceNow Wiki



I understand your question now:


".. the body always is null if haveError() is true. Is there any work around for this?"



However I do not have an answer for your inquiry.



Perhaps someone else could help out?



Best Regards



Tony


ducdhm
Giga Contributor

Seems like SNC changed in getBody() method of RESTResponseV2. Now I can get the body even haveError() is true


The problem still exists in case executeAsync() is using. In case HTTP status code is not 200 the getBody() always returns null. As result it's not possible to get custom error details from the body.



Tested on Fuji Patch 10 & Geneva Patch 5.


Ducdhm, are you doing anything different to getBody() when haveError() is true? I still get a null response when my status code != 200.


I'm with Eric, if the status code != 200, calling getBody() always returns null for me.