因此,基本上,客戶端使用Meteor.call
來調用服務器。服務器方法然後進行一些驗證並使用流星包調用Web服務。如果驗證失敗並拋出流星錯誤,則它會到達服務器。如果程序包響應有錯誤,它只會在服務器上登錄。我需要將錯誤傳達給客戶。投擲Meteor.Error沒有到達客戶端
下面是代碼的樣子。
客戶
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);
}
});
},
});
在服務器方法中,如果錯誤在錯誤1拋出,它到達客戶端,但錯誤2沒有。 錯誤2僅在服務器上登錄。
情況完全如此。我很抱歉,我完全忘記將此標記爲已接受 – nupac