- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2020 02:42 PM
Hi,
My requirement is to get the message and type from the response body. When I get status code 500, this is the response body I have. I am using the script include for calling the rest API and then calling this API in one of the UI actions. So I need to show this message and type I get in my response body when I click the UI action.
ResponseBody:
{
"error" : {
"type" : "SERVICE_EXCEPTION",
"message" : "MTA may be in use and determined to be not safe to suspend."
}
}
Any help would be appreciated!
Thanks,
Su
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2020 05:00 AM
Cool. Can you now replace
type = res.type;
message = res.message;
with
type = res.error.type;
message = res.error.message;
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2020 03:18 AM
Thanks,
I need to get the value of message and type, after parsing the response body.
Thanks,
Su

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2020 03:42 AM
Hi,
If you need type and message,then you can follow the below script,
After the above code mentioned:-
if(response){
var type = response.type;
var message = response.message;
gs.addInfoMessage("Response Type: "+type+ " And Message is: "+message);
}
If i was able to solve your query, please mark my answer correct and helpful.
Thanks & Regards
Prasant kumar sahu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2020 03:54 AM
It didn't work either.
var response = suspendRequest.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
var res = JSON.parse(responseBody);
if(res){
var type = res.type;
var message = res.message;
gs.info("Response Type: "+type+ " And Message is: "+message);
}
Also, tried this one, didn't work either...
if(response ){
var type = response .type;
var message = response .message;
gs.info("Response Type: "+type+ " And Message is: "+message);
}
Thanks