mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-22 13:50:49 +01:00
Refactor error handling for SendError struct
Reformat the construction of SendError objects for better readability. This improves the clarity and maintainability of the error handling code within the client.go file.
This commit is contained in:
parent
fcbd202595
commit
d400379e2f
1 changed files with 32 additions and 16 deletions
48
client.go
48
client.go
|
@ -798,13 +798,17 @@ func (c *Client) sendSingleMsg(message *Msg) error {
|
||||||
}
|
}
|
||||||
from, err := message.GetSender(false)
|
from, err := message.GetSender(false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &SendError{Reason: ErrGetSender, errlist: []error{err}, isTemp: isTempError(err),
|
return &SendError{
|
||||||
affectedMsg: message}
|
Reason: ErrGetSender, errlist: []error{err}, isTemp: isTempError(err),
|
||||||
|
affectedMsg: message,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
rcpts, err := message.GetRecipients()
|
rcpts, err := message.GetRecipients()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &SendError{Reason: ErrGetRcpts, errlist: []error{err}, isTemp: isTempError(err),
|
return &SendError{
|
||||||
affectedMsg: message}
|
Reason: ErrGetRcpts, errlist: []error{err}, isTemp: isTempError(err),
|
||||||
|
affectedMsg: message,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.dsn {
|
if c.dsn {
|
||||||
|
@ -813,8 +817,10 @@ func (c *Client) sendSingleMsg(message *Msg) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err = c.smtpClient.Mail(from); err != nil {
|
if err = c.smtpClient.Mail(from); err != nil {
|
||||||
retError := &SendError{Reason: ErrSMTPMailFrom, errlist: []error{err}, isTemp: isTempError(err),
|
retError := &SendError{
|
||||||
affectedMsg: message}
|
Reason: ErrSMTPMailFrom, errlist: []error{err}, isTemp: isTempError(err),
|
||||||
|
affectedMsg: message,
|
||||||
|
}
|
||||||
if resetSendErr := c.smtpClient.Reset(); resetSendErr != nil {
|
if resetSendErr := c.smtpClient.Reset(); resetSendErr != nil {
|
||||||
retError.errlist = append(retError.errlist, resetSendErr)
|
retError.errlist = append(retError.errlist, resetSendErr)
|
||||||
}
|
}
|
||||||
|
@ -843,28 +849,38 @@ func (c *Client) sendSingleMsg(message *Msg) error {
|
||||||
}
|
}
|
||||||
writer, err := c.smtpClient.Data()
|
writer, err := c.smtpClient.Data()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &SendError{Reason: ErrSMTPData, errlist: []error{err}, isTemp: isTempError(err),
|
return &SendError{
|
||||||
affectedMsg: message}
|
Reason: ErrSMTPData, errlist: []error{err}, isTemp: isTempError(err),
|
||||||
|
affectedMsg: message,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_, err = message.WriteTo(writer)
|
_, err = message.WriteTo(writer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &SendError{Reason: ErrWriteContent, errlist: []error{err}, isTemp: isTempError(err),
|
return &SendError{
|
||||||
affectedMsg: message}
|
Reason: ErrWriteContent, errlist: []error{err}, isTemp: isTempError(err),
|
||||||
|
affectedMsg: message,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
message.isDelivered = true
|
message.isDelivered = true
|
||||||
|
|
||||||
if err = writer.Close(); err != nil {
|
if err = writer.Close(); err != nil {
|
||||||
return &SendError{Reason: ErrSMTPDataClose, errlist: []error{err}, isTemp: isTempError(err),
|
return &SendError{
|
||||||
affectedMsg: message}
|
Reason: ErrSMTPDataClose, errlist: []error{err}, isTemp: isTempError(err),
|
||||||
|
affectedMsg: message,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = c.Reset(); err != nil {
|
if err = c.Reset(); err != nil {
|
||||||
return &SendError{Reason: ErrSMTPReset, errlist: []error{err}, isTemp: isTempError(err),
|
return &SendError{
|
||||||
affectedMsg: message}
|
Reason: ErrSMTPReset, errlist: []error{err}, isTemp: isTempError(err),
|
||||||
|
affectedMsg: message,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if err = c.checkConn(); err != nil {
|
if err = c.checkConn(); err != nil {
|
||||||
return &SendError{Reason: ErrConnCheck, errlist: []error{err}, isTemp: isTempError(err),
|
return &SendError{
|
||||||
affectedMsg: message}
|
Reason: ErrConnCheck, errlist: []error{err}, isTemp: isTempError(err),
|
||||||
|
affectedMsg: message,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue