do not crash if SMTP server is down

just log a warning if the SMTP server is down on startup time

fixes #3457
pull/3467/head
Girish Ramakrishnan 2020-12-11 12:02:32 -08:00 committed by Chocobozzz
parent fffc7c0864
commit 75594f474a
2 changed files with 5 additions and 6 deletions

View File

@ -249,7 +249,7 @@ async function startApplication () {
Emailer.Instance.init() Emailer.Instance.init()
await Promise.all([ await Promise.all([
Emailer.Instance.checkConnectionOrDie(), Emailer.Instance.checkConnection(),
JobQueue.Instance.init() JobQueue.Instance.init()
]) ])

View File

@ -107,18 +107,18 @@ class Emailer {
} }
} }
async checkConnectionOrDie () { async checkConnection () {
if (!this.transporter || CONFIG.SMTP.TRANSPORT !== 'smtp') return if (!this.transporter || CONFIG.SMTP.TRANSPORT !== 'smtp') return
logger.info('Testing SMTP server...') logger.info('Testing SMTP server...')
try { try {
const success = await this.transporter.verify() const success = await this.transporter.verify()
if (success !== true) this.dieOnConnectionFailure() if (success !== true) this.warnOnConnectionFailure()
logger.info('Successfully connected to SMTP server.') logger.info('Successfully connected to SMTP server.')
} catch (err) { } catch (err) {
this.dieOnConnectionFailure(err) this.warnOnConnectionFailure(err)
} }
} }
@ -636,9 +636,8 @@ class Emailer {
} }
} }
private dieOnConnectionFailure (err?: Error) { private warnOnConnectionFailure (err?: Error) {
logger.error('Failed to connect to SMTP %s:%d.', CONFIG.SMTP.HOSTNAME, CONFIG.SMTP.PORT, { err }) logger.error('Failed to connect to SMTP %s:%d.', CONFIG.SMTP.HOSTNAME, CONFIG.SMTP.PORT, { err })
process.exit(-1)
} }
static get Instance () { static get Instance () {