简体   繁体   中英

Global error message using Gulp Notify & Plumber

Is it possible to create a global OnError function that I can pass a title and the error message to?

I'm looking to do something like this for all tasks ran with plumber:

onError = function(error) {
      $.notify.onError({
        title:    'Error',
        subtitle: '<%= file.relative %> did not compile!',
        message:  '<%= error.message %>'   
      })(error);
    };

You can simply save the onError function as a variable:

var onError = notify.onError({
   title:    'Error',
   subtitle: '<%= file.relative %> did not compile!',
   message:  '<%= error.message %>'   
});

And in several different gulp-tasks and plumber-functions:

gulp.src('./src/*.ext')
  .pipe(plumber({ errorHandler: onError }))
  .pipe(coffee())
  .pipe(gulp.dest('./dist'));

and somewhere else:

gulp.src('./src/*.scss')
  .pipe(plumber({ errorHandler: onError }))
  .pipe(sass())
  .pipe(uglify())
  .pipe(plumber.stop())
  .pipe(gulp.dest('./dist'));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM