Refactor SendError initialization for better readability

Structured the initialization of SendError on connection errors to improve code readability and maintainability. This change affects the error handling in both client_120.go and client_119.go by spreading the error details across multiple lines.
This commit is contained in:
Winni Neessen 2024-11-14 10:20:52 +01:00
parent c8d7cf86e1
commit bd655b768b
Signed by: wneessen
GPG key ID: 385AC9889632126E
2 changed files with 8 additions and 4 deletions

View file

@ -32,8 +32,10 @@ func (c *Client) Send(messages ...*Msg) error {
escSupport, _ = c.smtpClient.Extension("ENHANCEDSTATUSCODES") escSupport, _ = c.smtpClient.Extension("ENHANCEDSTATUSCODES")
} }
if err := c.checkConn(); err != nil { if err := c.checkConn(); err != nil {
return &SendError{Reason: ErrConnCheck, errlist: []error{err}, isTemp: isTempError(err), return &SendError{
errcode: errorCode(err), enhancedStatusCode: enhancedStatusCode(err, escSupport)} Reason: ErrConnCheck, errlist: []error{err}, isTemp: isTempError(err),
errcode: errorCode(err), enhancedStatusCode: enhancedStatusCode(err, escSupport),
}
} }
var errs []*SendError var errs []*SendError
for id, message := range messages { for id, message := range messages {

View file

@ -32,8 +32,10 @@ func (c *Client) Send(messages ...*Msg) (returnErr error) {
escSupport, _ = c.smtpClient.Extension("ENHANCEDSTATUSCODES") escSupport, _ = c.smtpClient.Extension("ENHANCEDSTATUSCODES")
} }
if err := c.checkConn(); err != nil { if err := c.checkConn(); err != nil {
returnErr = &SendError{Reason: ErrConnCheck, errlist: []error{err}, isTemp: isTempError(err), returnErr = &SendError{
errcode: errorCode(err), enhancedStatusCode: enhancedStatusCode(err, escSupport)} Reason: ErrConnCheck, errlist: []error{err}, isTemp: isTempError(err),
errcode: errorCode(err), enhancedStatusCode: enhancedStatusCode(err, escSupport),
}
return return
} }