lib/server.js
function _wrap (handler, emitter) {
  return async (req, res) => {
    try {
      let response = await handler(req)

      await response.send(res)
    } catch (err) {
      // normalize
      if (! (err instanceof Error)) {
        err = new Error(`Non-error thrown: "${typeof err}"`)
      }

      // support ENOENT
      if (err.code === 'ENOENT') {
        err.expose = true
        err.status = 404
      }

      // send
      res.statusCode = err.status || err.statusCode || 500
      res.end()

      // delegate
      emitter.emit('error', err)
    }
  }
}
function _wrap (handler, emitter) {
  return async (req, res) => {
    try {
      let response = await handler(req)

      await response.send(res)
    } catch (err) {
      // normalize
      if (! (err instanceof Error)) {
        err = new Error(`Non-error thrown: "${typeof err}"`)
      }

      // support ENOENT
      if (err.code === 'ENOENT') {
        err.expose = true
        err.status = 404
      }

      // send
      res.statusCode = err.status || err.statusCode || 500
      res.end()

      // delegate
      emitter.emit('error', err)
    }
  }
}
function _wrap ( handler , emitter ) { return async ( req , res ) => { try { let response = await handler ( req ) await response . send ( res ) } catch ( err ) { // normalize if ( ! ( err instanceof Error ) ) { err = new Error ( ` ${ typeof err } ` ) } // support ENOENT if ( err . code === 'ENOENT' ) { err . expose = true err . status = 404 } // send res . statusCode = err . status || err . statusCode || 500 res . end ( ) // delegate emitter . emit ( 'error' , err ) } } }
Wrap the request handler

@param {Function} handler The request handler
@param {EventEmitter} emitter
@private
Wrap the request handler