How to parse response body?

tyagisu
Mega Expert

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

1 ACCEPTED SOLUTION

Cool. Can you now replace 

type = res.type;

message = res.message;

with 

type = res.error.type;

message = res.error.message;
Regards,
Muhammad

View solution in original post

17 REPLIES 17

please replace 

var httpStatus = res.getStatusCode(); 

with 

var httpStatus = response.getStatusCode(); 
Regards,
Muhammad

I replaced as you said. The output is:

Su response - [object Object]
Su message - undefined 
Su type - undefined 
Su Status- 500

Cool. Can you now replace 

type = res.type;

message = res.message;

with 

type = res.error.type;

message = res.error.message;
Regards,
Muhammad

Perfect! this works like a charm!

Thanks a lot.. 🙂

Glad It worked. Happy coding!

Thanks & Regards,

Sharjeel

Regards,
Muhammad