本文整理匯總了TypeScript中promise.reject函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript reject函數的具體用法?TypeScript reject怎麽用?TypeScript reject使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了reject函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: Promise
.then(function (result) {
if (result.rows.length === 0) return Promise.reject('User Not Found');
var promise = new Promise(function (resolve, reject) {
var hash = result.rows[0].password_hash;
bcrypt.compare(password, hash, function(err, res) {
if (res) resolve(result.rows[0].id);
else reject('Invalid password');
});
});
return promise
}, function (err) {
示例2: function
users.create = function (username : string, email : string, password :string) {
if (!validate(username, email, password)) return Promise.reject('invalid');
return users.usernameExists(username).then(function (exists) {
if (exists) throw new ex.UserException('That username is already taken!');
}).then(function () {
return users.emailExists(email)
}).then(function (exists) {
console.log(exists)
if (exists) throw new ex.UserException('That email is already in use!');
}).then(function () {
return hashPassword(password)
}).then(function (hash){
return database.runFunction(
'createuser',
[username, hash, email]
);
});
};
示例3:
.then(function (result) {
if (result.rows.length === 0) return Promise.reject('User Not Found');
else return result;
});