Improve email error logging

pull/6610/head
Chocobozzz 2024-09-05 15:43:43 +02:00
parent 853f311684
commit 99091da7c5
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 19 additions and 10 deletions

View File

@ -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
} }
} }

View File

@ -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
}