2018-06-28 03:10:34 +00:00
|
|
|
class SMTPError extends Error {
|
|
|
|
/**
|
|
|
|
* @param {string} message the error message
|
|
|
|
*/
|
|
|
|
constructor(message) {
|
|
|
|
super(message);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
this.code = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {*}
|
|
|
|
*/
|
|
|
|
this.smtp = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {Error}
|
|
|
|
*/
|
|
|
|
this.previous = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} message the error message
|
|
|
|
* @param {number} code the error code
|
|
|
|
* @param {Error} [error] an error object
|
|
|
|
* @param {*} [smtp] smtp
|
|
|
|
* @returns {SMTPError} an smtp error object
|
|
|
|
*/
|
2016-11-10 03:59:37 +00:00
|
|
|
module.exports = function(message, code, error, smtp) {
|
2018-06-28 03:10:34 +00:00
|
|
|
const err = new SMTPError(
|
|
|
|
error != null && error.message ? `${message} (${error.message})` : message
|
2018-05-27 04:25:08 +00:00
|
|
|
);
|
2018-05-14 23:02:16 +00:00
|
|
|
|
|
|
|
err.code = code;
|
2018-05-27 04:25:08 +00:00
|
|
|
err.smtp = smtp;
|
2011-02-23 21:23:37 +00:00
|
|
|
|
2018-05-14 23:02:16 +00:00
|
|
|
if (error) {
|
|
|
|
err.previous = error;
|
|
|
|
}
|
|
|
|
|
2018-05-27 04:25:08 +00:00
|
|
|
return err;
|
2012-08-03 11:24:20 +00:00
|
|
|
};
|
|
|
|
|
2018-06-29 03:25:10 +00:00
|
|
|
/**
|
|
|
|
* @type {1}
|
|
|
|
*/
|
2018-05-14 23:02:16 +00:00
|
|
|
module.exports.COULDNOTCONNECT = 1;
|
2018-06-29 03:25:10 +00:00
|
|
|
/**
|
|
|
|
* @type {2}
|
|
|
|
*/
|
2012-08-03 11:24:20 +00:00
|
|
|
module.exports.BADRESPONSE = 2;
|
2018-06-29 03:25:10 +00:00
|
|
|
/**
|
|
|
|
* @type {3}
|
|
|
|
*/
|
2012-08-03 11:24:20 +00:00
|
|
|
module.exports.AUTHFAILED = 3;
|
2018-06-29 03:25:10 +00:00
|
|
|
/**
|
|
|
|
* @type {4}
|
|
|
|
*/
|
2012-08-03 11:24:20 +00:00
|
|
|
module.exports.TIMEDOUT = 4;
|
2018-06-29 03:25:10 +00:00
|
|
|
/**
|
|
|
|
* @type {5}
|
|
|
|
*/
|
2012-08-03 11:24:20 +00:00
|
|
|
module.exports.ERROR = 5;
|
2018-06-29 03:25:10 +00:00
|
|
|
/**
|
|
|
|
* @type {6}
|
|
|
|
*/
|
2012-08-03 11:24:20 +00:00
|
|
|
module.exports.NOCONNECTION = 6;
|
2018-06-29 03:25:10 +00:00
|
|
|
/**
|
|
|
|
* @type {7}
|
|
|
|
*/
|
2012-08-03 11:24:20 +00:00
|
|
|
module.exports.AUTHNOTSUPPORTED = 7;
|
2018-06-29 03:25:10 +00:00
|
|
|
/**
|
|
|
|
* @type {8}
|
|
|
|
*/
|
2012-08-03 11:24:20 +00:00
|
|
|
module.exports.CONNECTIONCLOSED = 8;
|
2018-06-29 03:25:10 +00:00
|
|
|
/**
|
|
|
|
* @type {9}
|
|
|
|
*/
|
2012-08-03 11:24:20 +00:00
|
|
|
module.exports.CONNECTIONENDED = 9;
|
2018-06-29 03:25:10 +00:00
|
|
|
/**
|
|
|
|
* @type {10}
|
|
|
|
*/
|
2012-08-03 11:24:20 +00:00
|
|
|
module.exports.CONNECTIONAUTH = 10;
|