Skip to content

Instantly share code, notes, and snippets.

@paldepind
Last active August 29, 2015 14:10
Show Gist options
  • Save paldepind/bbd261e90e53013dcb1c to your computer and use it in GitHub Desktop.
Save paldepind/bbd261e90e53013dcb1c to your computer and use it in GitHub Desktop.
Ugly promise
var validateUser = function(user) {
return new Promise(function(resolve, reject) {
var validationError = c.validateFields(user, newUserRequiredFields, newUserAllowedFields);
if (validationError) {
reject(validationError);
} else {
checkUserExistence(user.username).then(resolve).catch(reject);
}
});
};
// Pretty promise
routes.validateUser = function(user) {
var validationError = c.validateFields(user, newUserRequiredFields, newUserAllowedFields);
return validationError ? Promise.reject(validationError)
: checkUserExistence(user.username);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment