mirror of
https://github.com/wneessen/go-mail.git
synced 2024-12-04 02:40:39 +01:00
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:
parent
e8fb977afe
commit
6268acac44
2 changed files with 18 additions and 18 deletions
32
client.go
32
client.go
|
@ -1201,16 +1201,16 @@ func (c *Client) sendSingleMsg(message *Msg) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &SendError{
|
return &SendError{
|
||||||
Reason: ErrGetSender, errlist: []error{err}, isTemp: isTempError(err),
|
Reason: ErrGetSender, errlist: []error{err}, isTemp: isTempError(err),
|
||||||
affectedMsg: message, errcode: getErrorCode(err),
|
affectedMsg: message, errcode: errorCode(err),
|
||||||
enhancedStatusCode: getEnhancedStatusCode(err, escSupport),
|
enhancedStatusCode: enhancedStatusCode(err, escSupport),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rcpts, err := message.GetRecipients()
|
rcpts, err := message.GetRecipients()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &SendError{
|
return &SendError{
|
||||||
Reason: ErrGetRcpts, errlist: []error{err}, isTemp: isTempError(err),
|
Reason: ErrGetRcpts, errlist: []error{err}, isTemp: isTempError(err),
|
||||||
affectedMsg: message, errcode: getErrorCode(err),
|
affectedMsg: message, errcode: errorCode(err),
|
||||||
enhancedStatusCode: getEnhancedStatusCode(err, escSupport),
|
enhancedStatusCode: enhancedStatusCode(err, escSupport),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1222,8 +1222,8 @@ 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{
|
retError := &SendError{
|
||||||
Reason: ErrSMTPMailFrom, errlist: []error{err}, isTemp: isTempError(err),
|
Reason: ErrSMTPMailFrom, errlist: []error{err}, isTemp: isTempError(err),
|
||||||
affectedMsg: message, errcode: getErrorCode(err),
|
affectedMsg: message, errcode: errorCode(err),
|
||||||
enhancedStatusCode: getEnhancedStatusCode(err, escSupport),
|
enhancedStatusCode: enhancedStatusCode(err, escSupport),
|
||||||
}
|
}
|
||||||
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)
|
||||||
|
@ -1242,8 +1242,8 @@ func (c *Client) sendSingleMsg(message *Msg) error {
|
||||||
rcptSendErr.errlist = append(rcptSendErr.errlist, err)
|
rcptSendErr.errlist = append(rcptSendErr.errlist, err)
|
||||||
rcptSendErr.rcpt = append(rcptSendErr.rcpt, rcpt)
|
rcptSendErr.rcpt = append(rcptSendErr.rcpt, rcpt)
|
||||||
rcptSendErr.isTemp = isTempError(err)
|
rcptSendErr.isTemp = isTempError(err)
|
||||||
rcptSendErr.errcode = getErrorCode(err)
|
rcptSendErr.errcode = errorCode(err)
|
||||||
rcptSendErr.enhancedStatusCode = getEnhancedStatusCode(err, escSupport)
|
rcptSendErr.enhancedStatusCode = enhancedStatusCode(err, escSupport)
|
||||||
hasError = true
|
hasError = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1257,23 +1257,23 @@ func (c *Client) sendSingleMsg(message *Msg) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &SendError{
|
return &SendError{
|
||||||
Reason: ErrSMTPData, errlist: []error{err}, isTemp: isTempError(err),
|
Reason: ErrSMTPData, errlist: []error{err}, isTemp: isTempError(err),
|
||||||
affectedMsg: message, errcode: getErrorCode(err),
|
affectedMsg: message, errcode: errorCode(err),
|
||||||
enhancedStatusCode: getEnhancedStatusCode(err, escSupport),
|
enhancedStatusCode: enhancedStatusCode(err, escSupport),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_, err = message.WriteTo(writer)
|
_, err = message.WriteTo(writer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &SendError{
|
return &SendError{
|
||||||
Reason: ErrWriteContent, errlist: []error{err}, isTemp: isTempError(err),
|
Reason: ErrWriteContent, errlist: []error{err}, isTemp: isTempError(err),
|
||||||
affectedMsg: message, errcode: getErrorCode(err),
|
affectedMsg: message, errcode: errorCode(err),
|
||||||
enhancedStatusCode: getEnhancedStatusCode(err, escSupport),
|
enhancedStatusCode: enhancedStatusCode(err, escSupport),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err = writer.Close(); err != nil {
|
if err = writer.Close(); err != nil {
|
||||||
return &SendError{
|
return &SendError{
|
||||||
Reason: ErrSMTPDataClose, errlist: []error{err}, isTemp: isTempError(err),
|
Reason: ErrSMTPDataClose, errlist: []error{err}, isTemp: isTempError(err),
|
||||||
affectedMsg: message, errcode: getErrorCode(err),
|
affectedMsg: message, errcode: errorCode(err),
|
||||||
enhancedStatusCode: getEnhancedStatusCode(err, escSupport),
|
enhancedStatusCode: enhancedStatusCode(err, escSupport),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
message.isDelivered = true
|
message.isDelivered = true
|
||||||
|
@ -1281,8 +1281,8 @@ func (c *Client) sendSingleMsg(message *Msg) error {
|
||||||
if err = c.Reset(); err != nil {
|
if err = c.Reset(); err != nil {
|
||||||
return &SendError{
|
return &SendError{
|
||||||
Reason: ErrSMTPReset, errlist: []error{err}, isTemp: isTempError(err),
|
Reason: ErrSMTPReset, errlist: []error{err}, isTemp: isTempError(err),
|
||||||
affectedMsg: message, errcode: getErrorCode(err),
|
affectedMsg: message, errcode: errorCode(err),
|
||||||
enhancedStatusCode: getEnhancedStatusCode(err, escSupport),
|
enhancedStatusCode: enhancedStatusCode(err, escSupport),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -265,7 +265,7 @@ func isTempError(err error) bool {
|
||||||
return err.Error()[0] == '4'
|
return err.Error()[0] == '4'
|
||||||
}
|
}
|
||||||
|
|
||||||
func getErrorCode(err error) int {
|
func errorCode(err error) int {
|
||||||
rootErr := errors.Unwrap(err)
|
rootErr := errors.Unwrap(err)
|
||||||
if rootErr != nil {
|
if rootErr != nil {
|
||||||
err = rootErr
|
err = rootErr
|
||||||
|
@ -282,7 +282,7 @@ func getErrorCode(err error) int {
|
||||||
return errcode
|
return errcode
|
||||||
}
|
}
|
||||||
|
|
||||||
func getEnhancedStatusCode(err error, supported bool) string {
|
func enhancedStatusCode(err error, supported bool) string {
|
||||||
if err == nil || !supported {
|
if err == nil || !supported {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue