refactor errors

This commit is contained in:
2024-10-14 13:29:05 -05:00
parent 1e33a81a2c
commit 39d4a1e7f0
20 changed files with 398 additions and 444 deletions

View File

@@ -2,7 +2,6 @@ package core
import (
"context"
"errors"
"fmt"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
@@ -51,9 +50,9 @@ func NewSESClient() SESClient {
}
func (s *SESClient) SendEmail(email Email) error {
if _, exists := s.ResetCache.Get(email.Recipient); exists {
return fmt.Errorf("email already sent to %s with subject %s", email.Recipient, email.Subject)
log.Printf("email already sent to %s with subject %s", email.Recipient, email.Subject)
return ErrEmailAlreadySent
}
// Load AWS configuration
@@ -61,7 +60,7 @@ func (s *SESClient) SendEmail(email Email) error {
if err != nil {
errMsg := fmt.Sprintf("unable to load SDK config, %v", err)
log.Print(errMsg)
return errors.New(errMsg)
return err
}
// Create an SES client
@@ -93,7 +92,9 @@ func (s *SESClient) SendEmail(email Email) error {
resp, err := sesClient.SendEmail(context.TODO(), input)
if err != nil {
s.ResetCache.Delete(email.Recipient)
return fmt.Errorf("failed to send email, %v", err)
errMsg := fmt.Sprintf("failed to send email, %v", err)
log.Print(errMsg)
return err
}
// Output the message ID of the sent email