refactor errors
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user