app/middlewares/errorHandler.js
/**
 * Return middleware that handle exceptions in Koa.
 * Dispose to the first middleware.
 *
 * @return {function} Koa middleware.
 */
Return middleware that handle exceptions in Koa.
Dispose to the first middleware.

@return {function} Koa middleware.
Return middleware that handle exceptions in Koa . Dispose to the first middleware . @return { function } Koa middleware .
function errorHandler() {
  return async (ctx, next) => {
    try {
      await next();
      if (!ctx.body && (!ctx.status || ctx.status === 404))
        ctx.res.notFound(UNKNOWN_ENDPOINT.code, UNKNOWN_ENDPOINT.message);
    } catch (err) {
      ctx.res.internalServerError(UNKNOWN_ERROR.code, UNKNOWN_ERROR.message);
      ctx.app.emit('error', err, ctx);
    }
  };
}
function errorHandler ( ) { return async ( ctx , next ) => { try { await next ( ) ; if ( ! ctx . body && ( ! ctx . status || ctx . status === 404 ) ) ctx . res . notFound ( UNKNOWN_ENDPOINT . code , UNKNOWN_ENDPOINT . message ) ; } catch ( err ) { ctx . res . internalServerError ( UNKNOWN_ERROR . code , UNKNOWN_ERROR . message ) ; ctx . app . emit ( 'error' , err , ctx ) ; } } ; }
Return middleware that handle exceptions in Koa.
Return middleware that handle exceptions in Koa .
// Respond 404 Not Found for unhandled request // Recommended for centralized error reporting, // retaining the default behaviour in Koa