code: function(err) {
      var errToStr = function(err) {
          var obj = {};
          Object.getOwnPropertyNames(err)
              .forEach(function(key) { obj[key] = err[key]; });
          return JSON.stringify(obj, null, 2);
      };
  
      var result = errToStr(err);
      if (typeof result === 'string') {
          result = result.replace(/\\n/g, '\n');
      }
      return result;
  }
docs: /*
  Stringifies an error object so that the stack is properly formatted in the
  console.
  
  @param {Error} err An error object to log or send.
  
  @return {string} A string representation of the error.