code: function setResponseErrors(err, obj) {
        /* jshint validthis: true */
        var self = this;
        obj = obj || {};
  
        if (err.data && err.data.errors) {
          err = err.data.errors;
        }
  
        if (err.errors) {
          err = err.errors;
        }
  
        angular.forEach(err, function (error, field) {
          if (self[field]) {
            self[field].$setValidity('mongoose', false);
          }
          obj[field] = error.type;
        });
      }
docs: Update validity of form fields that match the mongoose errors
  @param {Object} errors - The errors object to look for property names on
  @param {Object} [obj] - Object to attach all errors to
  @return {Object} An object with all fields mapped to the corresponding error