mailosaur / mailosaur-node

Mailosaur email and SMS testing library for Node.js
https://mailosaur.com/docs/languages/nodejs/
MIT License
20 stars 13 forks source link

message.js is throwing unhandled exceptions on communications errors #38

Closed davebachmann closed 4 years ago

davebachmann commented 4 years ago

An example of the pattern is

    self.client.request.get(url, (err, response, body) => {
      if (err || response.statusCode !== 200) {
        return reject(new MailosaurError(response));
      }
      resolve(new Message(body));

which is going to get an exception thrown from MailosaurError is response is null. In the case of a connect ETIMEDOUT the err parameter will be set to "connect ETIMEDOUTipAddress" and response will be null.

This should be something like:

    self.client.request.get(url, (err, response, body) => {
      if (err) {
        return reject(err);
      }
      if (response.statusCode !== 200) {
        return reject(new MailosaurError(response));
      }
      resolve(new Message(body));
jm-mailosaur commented 4 years ago

@davebachmann Thanks very much for this, this has now been fixed as part of version 7.0.2, the only other change in v7 is a restructure of the error model itself. 👍