Newbie in Promises here.
The documentation (as in the below image) tells it internally calls the onRejected function of catch block itself. So is there any use of having a catch block in a Promise if then is being provided with both the functions?
I tried throwing an error using throw 'error' and even Promise.reject('error') in the then block neither of which triggered the catch block.
Here's the sample code.
actionPromise = Promise.reject('error') // or throw 'Error'
actionPromise
.then(
(response) => next({ ...rest, response, type: SUCCESS }),
(error) => next({ ...rest, error, type: FAILURE }) // <--- Gets triggered
)
.catch((error) => {
console.error('MIDDLEWARE ERROR:', error); // <--- Not getting triggered
next({ ...rest, error, type: FAILURE });
});
