本文整理汇总了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;
});