Skip to content

Commit

Permalink
log OnMailAfter* hook errors in debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ganigeorgiev committed Dec 16, 2022
1 parent 687a79b commit 71d3f8f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
5 changes: 4 additions & 1 deletion mails/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mails

import (
"fmt"
"log"
"net/mail"

"github.com/pocketbase/pocketbase/core"
Expand Down Expand Up @@ -72,7 +73,9 @@ func SendAdminPasswordReset(app core.App, admin *models.Admin) error {
})

if sendErr == nil {
app.OnMailerAfterAdminResetPasswordSend().Trigger(event)
if err := app.OnMailerAfterAdminResetPasswordSend().Trigger(event); err != nil {
log.Println(err)
}
}

return sendErr
Expand Down
13 changes: 10 additions & 3 deletions mails/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mails

import (
"html/template"
"log"
"net/mail"

"github.com/pocketbase/pocketbase/core"
Expand Down Expand Up @@ -48,7 +49,9 @@ func SendRecordPasswordReset(app core.App, authRecord *models.Record) error {
})

if sendErr == nil {
app.OnMailerAfterRecordResetPasswordSend().Trigger(event)
if err := app.OnMailerAfterRecordResetPasswordSend().Trigger(event); err != nil && app.IsDebug() {
log.Println(err)
}
}

return sendErr
Expand Down Expand Up @@ -90,7 +93,9 @@ func SendRecordVerification(app core.App, authRecord *models.Record) error {
})

if sendErr == nil {
app.OnMailerAfterRecordVerificationSend().Trigger(event)
if err := app.OnMailerAfterRecordVerificationSend().Trigger(event); err != nil && app.IsDebug() {
log.Println(err)
}
}

return sendErr
Expand Down Expand Up @@ -135,7 +140,9 @@ func SendRecordChangeEmail(app core.App, record *models.Record, newEmail string)
})

if sendErr == nil {
app.OnMailerAfterRecordChangeEmailSend().Trigger(event)
if err := app.OnMailerAfterRecordChangeEmailSend().Trigger(event); err != nil && app.IsDebug() {
log.Println(err)
}
}

return sendErr
Expand Down

0 comments on commit 71d3f8f

Please sign in to comment.