出于某种原因,在我的网络应用中{I} throw new Meteor.Error('my-reason', 'Full details')
时,在客户端回调中,error.error
评估为403而不是“我的理由”。所以我在一个单独的文件夹中进行了快速测试:
if Meteor.isClient
Template.stuff.events
'click .throw': ->
Meteor.call 'throwError', 'dummy data', (error, result) ->
console.log error.error
if Meteor.isServer
Meteor.methods
throwError: (str) ->
throw new Meteor.Error 'work-please', 'Please work.'
果然,它很有效,error.error
是“工作愉快”。那么,为什么,在我正在开发的网络应用程序中,error.error
eval到403?来自所述网络应用的相关摘要:
createSeller: (userData) ->
check userData,
username: String
email: String
password: String
profile: Match.Optional Match.ObjectIncluding({accountType: String})
newUserId = Accounts.createUser
username: userData.username
email: userData.email
password: userData.password
profile:
accountType: 'seller'
if newUserId # successfully made new user
Accounts.sendVerificationEmail newUserId
return { success: true }
else
throw new Meteor.Error 'user-exists', 'User already exists.'
Meteor.call 'createSeller', newUser, (error, result) ->
Session.set 'creatingUser', false
console.log error.error
答案 0 :(得分:0)
我认为问题是从Accounts.createUser
的调用中抛出错误,而不是返回 错误,而不是您手动创建的错误,是什么被送回客户端。换句话说,你永远不会达到
else
throw new Meteor.Error 'user-exists', 'User already exists.'
因为在你到达那一点之前执行已经停止。
我认为您可以通过从Accounts.createUser
调用中删除错误来解决此问题:
try {
newUserId = Accounts.createUser
username: userData.username
email: userData.email
password: userData.password
profile:
accountType: 'seller'
} catch (err) {
throw new Meteor.Error 'user-exists', 'User already exists.'
}
// If you get to here you know there wasn't an error so no need for if statement
Accounts.sendVerificationEmail newUserId
return { success: true }