Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Improve email error logging

Chocobozzz99091da7c550
diff --git a/server/core/lib/emailer.ts b/server/core/lib/emailer.ts
index 63bf440467..6a4fc46c2a 100644
--- a/server/core/lib/emailer.ts
+++ b/server/core/lib/emailer.ts
@@ -271,6 +271,8 @@ class Emailer {
const toEmails = arrayify(options.to)
+ const errors: Error[] = []
+
for (const to of toEmails) {
const baseOptions: SendEmailDefaultOptions = {
template: 'common',
@@ -292,9 +294,22 @@ class Emailer {
// overridden/new variables given for a specific template in the payload
const sendOptions = merge(baseOptions, options)
- await email.send(sendOptions)
- .then(res => logger.debug('Sent email.', { res }))
- .catch(err => logger.error('Error in email sender.', { err }))
+ try {
+ const res = await email.send(sendOptions)
+
+ 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
}
}
diff --git a/server/core/lib/job-queue/handlers/email.ts b/server/core/lib/job-queue/handlers/email.ts
index 26b084e03d..539a8cce16 100644
--- a/server/core/lib/job-queue/handlers/email.ts
+++ b/server/core/lib/job-queue/handlers/email.ts
@@ -3,15 +3,9 @@ import { EmailPayload } from '@peertube/peertube-models'
import { logger } from '../../../helpers/logger.js'
import { Emailer } from '../../emailer.js'
-async function processEmail (job: Job) {
+export function processEmail (job: Job) {
const payload = job.data as EmailPayload
logger.info('Processing email in job %s.', job.id)
return Emailer.Instance.sendMail(payload)
}
-
-// ---------------------------------------------------------------------------
-
-export {
- processEmail
-}