How to handle errors on Meteor.wrapAsync?

203 views Asked by At

I have a meteor method where I am using the easy post api. Below is some asyncronous code which I expect to give an error from the EasyPost api (because it is an invalid address).

EasyPost = Easypost("<you don't get to see my api key>");
EasyPost.Address.create_and_verify(address, function (err, response) {
  console.log(err);
});

This gives me the following response, which is what I expect.

{
  message: {
    code: "ADDRESS.VERIFY.FAILURE",
    message: "Address Not Found",
    errors: []
  },
  param: undefined
}

I want to try and make this syncronous, so I tried the following, but my meteor shell always logs [Object object]

> var createAndVerifySync = Meteor.wrapAsync(EasyPost.Address.create_and_verify, EasyPost.Address);
> createAndVerifySync(address);
[object Object]

I suspect this has to do with the error message from EasyPost returning as an object. How could I create a wrapper around the asyncronous methods of EasyPost with the inclusion of Meteor and futures?

1

There are 1 answers

0
Justin Hammond On

For future travelers, this was answered via this comments by @mwarren on this question.