From 6268acac445150cfab834b293e7e5575ec9f2ab5 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Wed, 13 Nov 2024 22:47:53 +0100 Subject: [PATCH] Refactor error handling by renaming functions. Renamed `getErrorCode` to `errorCode` and `getEnhancedStatusCode` to `enhancedStatusCode` for consistency. Updated all references in `client.go` and `senderror.go` accordingly, improving readability and maintaining uniformity across the codebase. --- client.go | 32 ++++++++++++++++---------------- senderror.go | 4 ++-- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/client.go b/client.go index d64c172..9b3251e 100644 --- a/client.go +++ b/client.go @@ -1201,16 +1201,16 @@ func (c *Client) sendSingleMsg(message *Msg) error { if err != nil { return &SendError{ Reason: ErrGetSender, errlist: []error{err}, isTemp: isTempError(err), - affectedMsg: message, errcode: getErrorCode(err), - enhancedStatusCode: getEnhancedStatusCode(err, escSupport), + affectedMsg: message, errcode: errorCode(err), + enhancedStatusCode: enhancedStatusCode(err, escSupport), } } rcpts, err := message.GetRecipients() if err != nil { return &SendError{ Reason: ErrGetRcpts, errlist: []error{err}, isTemp: isTempError(err), - affectedMsg: message, errcode: getErrorCode(err), - enhancedStatusCode: getEnhancedStatusCode(err, escSupport), + affectedMsg: message, errcode: errorCode(err), + enhancedStatusCode: enhancedStatusCode(err, escSupport), } } @@ -1222,8 +1222,8 @@ func (c *Client) sendSingleMsg(message *Msg) error { if err = c.smtpClient.Mail(from); err != nil { retError := &SendError{ Reason: ErrSMTPMailFrom, errlist: []error{err}, isTemp: isTempError(err), - affectedMsg: message, errcode: getErrorCode(err), - enhancedStatusCode: getEnhancedStatusCode(err, escSupport), + affectedMsg: message, errcode: errorCode(err), + enhancedStatusCode: enhancedStatusCode(err, escSupport), } if resetSendErr := c.smtpClient.Reset(); resetSendErr != nil { retError.errlist = append(retError.errlist, resetSendErr) @@ -1242,8 +1242,8 @@ func (c *Client) sendSingleMsg(message *Msg) error { rcptSendErr.errlist = append(rcptSendErr.errlist, err) rcptSendErr.rcpt = append(rcptSendErr.rcpt, rcpt) rcptSendErr.isTemp = isTempError(err) - rcptSendErr.errcode = getErrorCode(err) - rcptSendErr.enhancedStatusCode = getEnhancedStatusCode(err, escSupport) + rcptSendErr.errcode = errorCode(err) + rcptSendErr.enhancedStatusCode = enhancedStatusCode(err, escSupport) hasError = true } } @@ -1257,23 +1257,23 @@ func (c *Client) sendSingleMsg(message *Msg) error { if err != nil { return &SendError{ Reason: ErrSMTPData, errlist: []error{err}, isTemp: isTempError(err), - affectedMsg: message, errcode: getErrorCode(err), - enhancedStatusCode: getEnhancedStatusCode(err, escSupport), + affectedMsg: message, errcode: errorCode(err), + enhancedStatusCode: enhancedStatusCode(err, escSupport), } } _, err = message.WriteTo(writer) if err != nil { return &SendError{ Reason: ErrWriteContent, errlist: []error{err}, isTemp: isTempError(err), - affectedMsg: message, errcode: getErrorCode(err), - enhancedStatusCode: getEnhancedStatusCode(err, escSupport), + affectedMsg: message, errcode: errorCode(err), + enhancedStatusCode: enhancedStatusCode(err, escSupport), } } if err = writer.Close(); err != nil { return &SendError{ Reason: ErrSMTPDataClose, errlist: []error{err}, isTemp: isTempError(err), - affectedMsg: message, errcode: getErrorCode(err), - enhancedStatusCode: getEnhancedStatusCode(err, escSupport), + affectedMsg: message, errcode: errorCode(err), + enhancedStatusCode: enhancedStatusCode(err, escSupport), } } message.isDelivered = true @@ -1281,8 +1281,8 @@ func (c *Client) sendSingleMsg(message *Msg) error { if err = c.Reset(); err != nil { return &SendError{ Reason: ErrSMTPReset, errlist: []error{err}, isTemp: isTempError(err), - affectedMsg: message, errcode: getErrorCode(err), - enhancedStatusCode: getEnhancedStatusCode(err, escSupport), + affectedMsg: message, errcode: errorCode(err), + enhancedStatusCode: enhancedStatusCode(err, escSupport), } } return nil diff --git a/senderror.go b/senderror.go index 93ab6f2..e32d74b 100644 --- a/senderror.go +++ b/senderror.go @@ -265,7 +265,7 @@ func isTempError(err error) bool { return err.Error()[0] == '4' } -func getErrorCode(err error) int { +func errorCode(err error) int { rootErr := errors.Unwrap(err) if rootErr != nil { err = rootErr @@ -282,7 +282,7 @@ func getErrorCode(err error) int { return errcode } -func getEnhancedStatusCode(err error, supported bool) string { +func enhancedStatusCode(err error, supported bool) string { if err == nil || !supported { return "" }