Should a Promise.reject message be wrapped in Error?

Yes, it most definitely should. A string is not an error, when you have errors usually it means something went wrong which means you’d really enjoy a good stack trace. No error – no stack trace.

Just like with try/catch, if you add .catch to a thrown rejection, you want to be able to log the stack trace, throwing strings ruins that for you.

I’m on mobile so this answer is rather short but I really can’t emphasize enough how important this is. In large (10K+ LoC) apps stack traces in rejections really made the difference between easy remote bug hunting and a long night in the office.

Leave a Comment