nucliweb
12/9/2015 - 3:35 PM

ERROR HANDLER

ERROR HANDLER

var beep = require('beepbeep');
var colors = require('colors');

var onError = function(err) {
  beep([200, 200]);

  var formatOutput = function(context) {
    var msg, file, line, description;

    if(context == 'gulp-babel') {
      file = String(err.fileName);
      line = String(err.loc.line);
      description = String(err.name + err.message.replace(err.fileName, ''));
    } else if(err.plugin == 'gulp-sass') {
      file = String(err.relativePath);
      line = String(err.line);
      description = String(err.messageOriginal);
    } else {
      file = '';
      line = '';
      description = err;
    }

    msg =
      'file: '.bold.white  + file.bold.green  + '\n' +
      'line: '.bold.white + line.bold.green + '\n\n' +
      description.bold.red + '\n';

    return msg
  }

  var errorMsg = formatOutput(err.plugin);

  console.log(
    '\n\n******************************************\n'.bold.gray +
    ' ***********'.bold.gray +
    ' \(╯°□°)╯'.bold.magenta + ' ︵ '.bold.blue + 'ɹoɹɹǝ '.bold.red +
    '***********'.bold.gray +
    '\n******************************************\n\n'.bold.gray +
    errorMsg +
    '\n******************************************\n\n'.bold.gray);
  this.emit('end');
};