I am catching errors from an Ajax response. The kind of error that comes back depends on where it was thrown and I need to look out for certain ones.
I know the error variable always exists but past this I have to check the existence for each level, otherwise risk getting a TypeError: Cannot read property '0' of undefined error.
I am currently doing:
if (error.response && error.response.data && error.response.data.errors
&& error.response.data.errors[0].title === 'no_space') {
//do something
}
But there must be a better way?
&& error.response.data.errors[0] &&...error.response.data.errorsseems rather redundant to begin with.