I have a result like this
{
"Errors" : {
"Failure" : {
"ShowAsPopup" : true,
"ErrorMessage" :"Some Message.",
"PopupTitle" : null
}
},
"IsValid" : false,
"WarningMessage" : null,
"SuccessMessage" : null
}
now if I do Errors.Failure.ShowAsPopup I get a value. What is expected. However I want to use index instead(if that is possible)
I tried
Errors[0].Failure.ShowAsPopup but this just gives me undefined. Ideal I would like to have it like Errors[0].[0].ShowAsPopup where I don’t have to specify the “Failure” but I might have to rethink that part.
I want a generic way to handle my errors. See some errors require a popup and some are just validation errors. So right now I have them all hardcoded and I am trying to get away from that. I rather just check if that error requires a popup or not.
So instead of
if(response.Errors.Failure) { // alert('hi')};
else if(response.Errors.Failure2 {// alert('hi2')}
and so on I would just have one if statement that could do the check.
1 Answer