pedronauck / micro-router

:station: A tiny and functional router for Zeit's Micro

Home Page:https://www.npmjs.com/microrouter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crashing micro when throwing errors on Promises

olivermaldonado opened this issue · comments

The router causes micro to crash when errors are thrown on Promises.

module.exports = router(
  get('/badError', (req, res) => {
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        throw new Error('deferred error')
      }, 1000)
    })
  }),
  get('goodError', (req, res) => {
    throw new Error('immediate error')
  })
)

Is this intended behavior?

One of the advantages of using micro is it's error handling. This issue breaks that.

This is not an error with micro-router or micro.

The deferred error is thrown from the context of the setTimeout callback which is not in the promise chain.