All files / lib/Errors BatchError.js

100% Statements 13/13
100% Branches 9/9
100% Functions 2/2
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27  6x 1x   6x 6x 4x 4x   6x         6x 6x 6x 6x           6x   6x  
function getBatchedMessage(errors) {
  if (!Array.isArray(errors)) {
    errors = [];
  }
  let message = '';
  for (const error of errors) {
    const _message = `${error.message}\n\t\t${error.stack}`;
    message += `\t${_message}\n`;
  }
  return message;
}
 
class BatchError extends Error {
  constructor(message, errors = []) {
    message += `\n${getBatchedMessage(errors)}`;
    message += `Total: ${errors && errors.length ? errors.length : 0}`;
    super(message);
    this.errors = Array.isArray(errors) ? errors : [];
  }
}
 
// Just for use if some one will chahge the getBatchedMessage & he will need
// super.getBatchedMessage
BatchError.prototype.getBatchedMessage = getBatchedMessage;
 
module.exports = BatchError;