Improve email error logging
This commit is contained in:
parent
853f311684
commit
99091da7c5
|
@ -271,6 +271,8 @@ class Emailer {
|
||||||
|
|
||||||
const toEmails = arrayify(options.to)
|
const toEmails = arrayify(options.to)
|
||||||
|
|
||||||
|
const errors: Error[] = []
|
||||||
|
|
||||||
for (const to of toEmails) {
|
for (const to of toEmails) {
|
||||||
const baseOptions: SendEmailDefaultOptions = {
|
const baseOptions: SendEmailDefaultOptions = {
|
||||||
template: 'common',
|
template: 'common',
|
||||||
|
@ -292,9 +294,22 @@ class Emailer {
|
||||||
// overridden/new variables given for a specific template in the payload
|
// overridden/new variables given for a specific template in the payload
|
||||||
const sendOptions = merge(baseOptions, options)
|
const sendOptions = merge(baseOptions, options)
|
||||||
|
|
||||||
await email.send(sendOptions)
|
try {
|
||||||
.then(res => logger.debug('Sent email.', { res }))
|
const res = await email.send(sendOptions)
|
||||||
.catch(err => logger.error('Error in email sender.', { err }))
|
|
||||||
|
logger.debug('Sent email.', { res })
|
||||||
|
} catch (err) {
|
||||||
|
errors.push(err)
|
||||||
|
|
||||||
|
logger.error('Error in email sender.', { err })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errors.length !== 0) {
|
||||||
|
const err = new Error('Some errors when sent emails') as Error & { errors: Error[] }
|
||||||
|
err.errors = errors
|
||||||
|
|
||||||
|
throw err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,15 +3,9 @@ import { EmailPayload } from '@peertube/peertube-models'
|
||||||
import { logger } from '../../../helpers/logger.js'
|
import { logger } from '../../../helpers/logger.js'
|
||||||
import { Emailer } from '../../emailer.js'
|
import { Emailer } from '../../emailer.js'
|
||||||
|
|
||||||
async function processEmail (job: Job) {
|
export function processEmail (job: Job) {
|
||||||
const payload = job.data as EmailPayload
|
const payload = job.data as EmailPayload
|
||||||
logger.info('Processing email in job %s.', job.id)
|
logger.info('Processing email in job %s.', job.id)
|
||||||
|
|
||||||
return Emailer.Instance.sendMail(payload)
|
return Emailer.Instance.sendMail(payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
export {
|
|
||||||
processEmail
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue