My meteorite code at some points goes through several Meteor.call methods. If I have an error in the second layer and I want to throw this meteor error back to the client side, how can I do this?
I currently have something like this, but I get very confusing results, and I donβt think I fully understand what happens when I call throw new Meteor.Error(500, e.category_code, e.description);
In client.js
Meteor.call('firstCall', data, function (error, result) { if(result) { doSomething(); } else{ console.log(error);
In server.js
var Future = Meteor.npmRequire("fibers/future"); function extractFromPromise(promise) { var fut = new Future(); promise.then(function (result) { fut.return(result); }, function (error) { console.log(error); fut.throw(error); }); return fut.wait(); } firstCall: function (data){ try{ Meteor.call('secondCall', data, 'http://testhref.com/test', 'http://testhref2.com/test' function (error, result) { return result; }); } catch(e){ throw new Meteor.Error(500, e.category_code, e.description); } } secondCall: function (data, paymentHref, otherHref){ try{ var associate = extractFromPromise(balanced.get(paymentHref).associate_to_customer(otherHref).debit({ "amount": data.paymentInformation[0].total_amount * 100, "appears_on_statement_as": "Trash Mountain"})); } catch(e){ Collection.update(data.id, { $set: { 'failed.category_code': e.category_code, 'failed.description': e.description } }); throw new Meteor.Error(500, e.category_code, e.description); } }
source share