function errorJSON(err) {
    var res = {};
    Object.getOwnPropertyNames(err).forEach(function (key) {
      res[key] = err[key];
    }, err);
    return res;
  }
Transform an Error object into a JSON object.

@private
@param {Error} err
@return {Object}