Mailspring/packages/isomorphic-core/src/errors.es6
Christine Spang a57e4bdd20 [cloud-api] Verify SMTP credentials in /auth endpoint
Summary:
This patch will prevent users from being able to connect accounts which sync
mail but fail to send.

This commit includes a couple pieces:
* Adds a call to nodemailer's `verify()` function in the /auth endpoint
* Adds Error object conversion for SMTP errors. Since we don't implement our
  own connection object or connection pool for SMTP, we simply wrap the couple
  places we call functions from nodemailer that connect to SMTP, namely
  SendmailClient's _send() and the new verify() call in /auth.
* Moves RetryableError to the 'errors' module since it's now a base class for
  retryable IMAP //and// SMTP errors.
* Moves the main `smtpConfig()` logic which used to live on the Account model
  into AuthHelpers so it can be shared between the Account model and the verify
  code.
* Converts a few different places to use `import` syntax instead of
  `require` syntax for module imports. Apologies for not splitting this out
  into a separate diff—would have been a fair amount of work and looks not too
  difficult to skim over in the context of the rest of the patch.
* Fixing a bug in a previous commit where erroring sends would crash because of
  using `this._transporter.options` instead of `this._transporter.transporter.options`

Test Plan: manual

Reviewers: evan, halla, juan

Reviewed By: halla, juan

Differential Revision: https://phab.nylas.com/D4200
2017-03-28 15:47:44 -07:00

27 lines
645 B
JavaScript

export class NylasError extends Error {
toJSON() {
let json = {}
if (super.toJSON) {
// Chromium `Error`s have a `toJSON`, but Node `Error`s do NOT!
json = super.toJSON()
}
Object.getOwnPropertyNames(this).forEach((key) => {
json[key] = this[key];
});
return json
}
}
export class APIError extends NylasError {
constructor(message, statusCode, data) {
super(message);
this.statusCode = statusCode;
this.data = data;
}
}
/**
* An abstract base class that can be used to indicate Errors that may fix
* themselves when retried
*/
export class RetryableError extends NylasError { }