function makeError(message, data) {
  var err = new Error(message);

  for (var k in data) {
    err[k] = data[k];
  }

  return err;
}
Little helper returning a JavaScript error carrying some data with it.

@param  {string} message - The error message.
@param  {object} [data]  - Optional data to assign to the error.
@return {Error}          - The created error.