Last active
August 29, 2015 14:10
-
-
Save paldepind/bbd261e90e53013dcb1c to your computer and use it in GitHub Desktop.
Ugly promise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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