Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to extract only certain sentences

Exception: Request failed for https://test123.my.salesforce.com returned code 400. Truncated server response: [{"message":"Use one of these records?","errorCode":"UNKNOWN_EXCEPTION","fields":[]}] (use muteHttpExceptions option to examine full response)


Exception: Request failed for https://test123.my.salesforce.com returned code 400. Truncated server response: [{"message”:”myNum: value outside of valid range on numeric field: 100.0","errorCode":"NUMBER_OUTSIDE_VALID_RANGE","fields”:[“myNum”__c]}] (use muteHttpExceptions option to examine full response)

I want to extract only the message part from the following sentence.

"Use one of these records?"

”myNum: value outside of valid range on numeric field: 100.0"

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I tried a few ways, but it didn’t work out.

I tried using split and slice,
The format of the error message has changed and it has not come out properly.

var response_code = error.toString();
var slice = response_code.split(':')[4]
var errormessage = (slice||'').split(',')[0]

There are results that come out as I want,

"Use one of these records?"

Some of the results were cut off.

"myNum

What should I do?

>Solution :

Assuming that the JSON key "message" would be relatively unique in your log statements, you could use match() as follows:

var messages = ["Exception: Request failed for https://test123.my.salesforce.com returned code 400. Truncated server response: [{\"message\":\"Use one of these records?\",\"errorCode\":\"UNKNOWN_EXCEPTION\",\"fields\":[]}] (use muteHttpExceptions option to examine full response)",
"Exception: Request failed for https://test123.my.salesforce.com returned code 400. Truncated server response: [{\"message\":\"myNum: value outside of valid range on numeric field: 100.0\",\"errorCode\":\"NUMBER_OUTSIDE_VALID_RANGE\",\"fields\":[\"myNum\"__c]}] (use muteHttpExceptions option to examine full response)"];
var outputs = messages.map(x => x.match(/"message":"(.*?)"/)[1]);
console.log(outputs);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading