I have a simple Promise that I execute:
function handleCall(url) {
return new Promise((resolve, reject) => {
xhr.get(url).then(
resolve,
err => {
if (!reject(err)) {
// Handle here the error in a generic way
}
}
)
}
)
The idea here is to let me handle the error when I want, by adding a .catch to the handleCall method, but if there is no catch mechanism, the handleCall would fall back to the default actions defined in that function.
Of course, my above code doesn't work, the reject function returns null even if my custom catch returns something.
I tried with a try/catch block instead, in the idea that "if no catch method is defined when calling, then an exception might be thrown", but it's not working either.
Is there a way to achieve this? I mean, letting the caller of handleCall handle the error, but if no error has been implemented (no catch), then fallback to the generic one on handleCall?