I have the response that is used for all our error messages and the one variable that contains the error message has a dynamic label. Wondering how I can access to display the error only.
Response:
{
“type”: “dolore anim”,
“title”: “labore”,
“status”: -77902739,
“detail”: “non laborum ad consequat”,
“instance”: “Duis nisi”,
“errors”: {
“ex_c9”: [
“mollit ad”,
“ad fugiat occae”
],
“ut90e”: [
“voluptate aliquip do laboris”,
“proident quis veniam tempor exercitation”
]
}
}
The variable that is bolded is what will change depending on the error.
In this screenshot the error is $.isSystem yet in another error it could be $.permissions.admin. I can print it on the console but would like to print it during the test run as a test.
Example:
pm.test(savedData, () =>{
“test script info”
});
I’ve already tried:
jsonData.errors.errors[0]
jsonData.errors.$
These come back with an undefined error.
let response = pm.response.json(),
savedData = JSON.stringify(response);
pm.collectionVariables.set(“savedData”, savedData);
console.log(savedData)
I have save it to a collection variable but again it is the entire error message with title, traceID, etc, listed when all I want is the errors.$.Variable value.
console.log(jsonData.errors)
When I try to use the jsonData.errors by itself I just get object, Object. So how can I access the $.variable object within the errors object?