There are some things you need to be aware of when handling exceptions in promises. If you are not careful an exception can be swallowed and the caller of the promise will never known an exception occured.
Therefore you should always take the following rules into account:
- Add global exception handling to your promise chain by ending with a catch block.
- Return a rejected promise if you want to maintain the exception in the promise chain.
So don’t do this:
Instead return a rejected promise in your catch block: