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.
This commit is contained in:
Winni Neessen 2024-11-13 22:47:53 +01:00
parent e8fb977afe
commit 6268acac44
Signed by: wneessen
GPG key ID: 385AC9889632126E
2 changed files with 18 additions and 18 deletions

View file

@ -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

View file

@ -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 ""
}