lib/application.js
function onResError (ctx, err) {
  // nothing we can do here other
  // than delegate to the app-level
  // handler and log.
  if (ctx.headerSent || ctx._finished != null) {
    err.headerSent = ctx.headerSent
    err.context = ctx.toJSON()
    return err
  }

  // unset headers
  if (isFn(ctx.res.getHeaderNames)) {
    for (let name of ctx.res.getHeaderNames()) {
      if (!ON_ERROR_HEADER_REG.test(name)) ctx.res.removeHeader(name)
    }
  } else { // Node < 7.7
    let _headers = ctx.res._headers
    if (_headers) {
      // retain headers on error
      for (let name of Object.keys(_headers)) {
        if (!ON_ERROR_HEADER_REG.test(name)) delete _headers[name]
      }
    }
  }
  // support ENOENT to 404, default to 500
  if (err.code === 'ENOENT') ctx.status = 404
  else if (typeof err.status !== 'number' || !statuses[err.status]) ctx.status = 500
  else ctx.status = err.status

  ctx.set('x-content-type-options', 'nosniff')
  // support JSON error object: { error: 'BadRequest', message: 'Some bad request' }
  ctx.body = !isError(err) ? err : {
    error: err.error || err.name,
    message: err.expose ? err.message : statuses[ctx.status]
  }
  respond.call(ctx)
  return err
}
function onResError (ctx, err) {
  // nothing we can do here other
  // than delegate to the app-level
  // handler and log.
  if (ctx.headerSent || ctx._finished != null) {
    err.headerSent = ctx.headerSent
    err.context = ctx.toJSON()
    return err
  }

  // unset headers
  if (isFn(ctx.res.getHeaderNames)) {
    for (let name of ctx.res.getHeaderNames()) {
      if (!ON_ERROR_HEADER_REG.test(name)) ctx.res.removeHeader(name)
    }
  } else { // Node < 7.7
    let _headers = ctx.res._headers
    if (_headers) {
      // retain headers on error
      for (let name of Object.keys(_headers)) {
        if (!ON_ERROR_HEADER_REG.test(name)) delete _headers[name]
      }
    }
  }
  // support ENOENT to 404, default to 500
  if (err.code === 'ENOENT') ctx.status = 404
  else if (typeof err.status !== 'number' || !statuses[err.status]) ctx.status = 500
  else ctx.status = err.status

  ctx.set('x-content-type-options', 'nosniff')
  // support JSON error object: { error: 'BadRequest', message: 'Some bad request' }
  ctx.body = !isError(err) ? err : {
    error: err.error || err.name,
    message: err.expose ? err.message : statuses[ctx.status]
  }
  respond.call(ctx)
  return err
}
function onResError ( ctx , err ) { // nothing we can do here other // than delegate to the app-level // handler and log. if ( ctx . headerSent || ctx . _finished != null ) { err . headerSent = ctx . headerSent err . context = ctx . toJSON ( ) return err } // unset headers if ( isFn ( ctx . res . getHeaderNames ) ) { for ( let name of ctx . res . getHeaderNames ( ) ) { if ( ! ON_ERROR_HEADER_REG . test ( name ) ) ctx . res . removeHeader ( name ) } } else { // Node < 7.7 let _headers = ctx . res . _headers if ( _headers ) { // retain headers on error for ( let name of Object . keys ( _headers ) ) { if ( ! ON_ERROR_HEADER_REG . test ( name ) ) delete _headers [ name ] } } } // support ENOENT to 404, default to 500 if ( err . code === 'ENOENT' ) ctx . status = 404 else if ( typeof err . status !== 'number' || ! statuses [ err . status ] ) ctx . status = 500 else ctx . status = err . status ctx . set ( 'x-content-type-options' , 'nosniff' ) // support JSON error object: { error: 'BadRequest', message: 'Some bad request' } ctx . body = ! isError ( err ) ? err : { error : err . error || err . name , message : err . expose ? err . message : statuses [ ctx . status ] } respond . call ( ctx ) return err }
Default response error handler.

@param {Error} err
@api private
Default response error handler .