在 error.error 中总是 Meteor.Error 抛出 returns 403
Throwing Meteor.Error always returns 403 in error.error
出于某种原因,在我的网络应用程序中,当我 throw new Meteor.Error('my-reason', 'Full details')
时,在客户端回调中,error.error
评估为 403 而不是 "my-reason." 所以我在一个单独的环境中进行了快速测试文件夹:
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
是 "work-please." 那么,为什么在我正在开发的网络应用程序中,error.error
求值为 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
我认为问题是从调用 Accounts.createUser
和 that 错误中抛出错误,而不是返回错误,而不是您手动输入的错误创建,是什么被发送回客户端。换句话说,你永远达不到
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 }
出于某种原因,在我的网络应用程序中,当我 throw new Meteor.Error('my-reason', 'Full details')
时,在客户端回调中,error.error
评估为 403 而不是 "my-reason." 所以我在一个单独的环境中进行了快速测试文件夹:
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
是 "work-please." 那么,为什么在我正在开发的网络应用程序中,error.error
求值为 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
我认为问题是从调用 Accounts.createUser
和 that 错误中抛出错误,而不是返回错误,而不是您手动输入的错误创建,是什么被发送回客户端。换句话说,你永远达不到
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 }