lib/utils/compose.js
function handleError(promise) {
      if (canHandleError) {
        return promise.catch(function(err) {
          if (ctx) {
            ctx.error = err;
            if (ctx.emit) ctx.emit('error', ctx);
          } else {
            ctx = { error: err };
          }
          return onError(ctx, next).catch(function(err) {
            // Log catched error in onError
            logError(`[${new Date()}] ${err.name || err.message} \n ${err.stack}`);
          });
        });
      } else {
        return promise;
      }
    }
function handleError(promise) {
      if (canHandleError) {
        return promise.catch(function(err) {
          if (ctx) {
            ctx.error = err;
            if (ctx.emit) ctx.emit('error', ctx);
          } else {
            ctx = { error: err };
          }
          return onError(ctx, next).catch(function(err) {
            // Log catched error in onError
            logError(`[${new Date()}] ${err.name || err.message} \n ${err.stack}`);
          });
        });
      } else {
        return promise;
      }
    }
function handleError ( promise ) { if ( canHandleError ) { return promise . catch ( function ( err ) { if ( ctx ) { ctx . error = err ; if ( ctx . emit ) ctx . emit ( 'error' , ctx ) ; } else { ctx = { error : err } ; } return onError ( ctx , next ) . catch ( function ( err ) { // Log catched error in onError logError ( ` ${ new Date ( ) } ${ err . name || err . message } \n ${ err . stack } ` ) ; } ) ; } ) ; } else { return promise ; } }
Handle possible error for each promise
Handle possible error for each promise