【发布时间】:2016-12-06 01:05:35
【问题描述】:
所以基本上,客户端使用Meteor.call 调用服务器。然后,服务器方法进行一些验证并使用流星包调用 Web 服务。如果验证失败并且抛出一个流星错误,它会到达服务器。如果包响应有错误,它只会登录服务器。我需要错误信息才能联系到客户。
代码如下所示。
客户
Meteor.call('callService', (err, result) => {
if(err) {
console.log(err.reason);
}
});
服务器
Meteor.methods({
'callService'(){
if (!Meteor.user()) {
// Error 1
throw new Meteor.Error('insufficient-permissions', 'You need to login first');
}
// Using an meteor package to actually call the service
package.callService(apiKey, (err, response) => {
if (response.status === 'error') {
// Error 2
throw new Meteor.Error('service-error', response.message);
}
});
},
});
在服务器方法中,如果在 Error 1 处抛出错误,它确实会到达客户端,但 Error 2 不会。 错误2只登录服务器。
【问题讨论】:
标签: meteor