fix: Upgrade error handling to errors/v2 package and refactor error messages.

- Refactor error handling using `errors/v2` package for improved error management and formatting
- Implement changes in relay/controller/text.go, controller/channel-test.go, controller/relay.go, common/message/email.go, relay/controller/audio.go, controller/channel-billing.go, relay/controller/helper.go, relay/channel/common.go, relay/channel/minimax/main.go, and common/message/main.go
- Add package imports and update package paths for better code organization
- Replace hardcoded strings with error variables for consistency and readability
- Implement secure methods for generating unique Message-ID
- Improve SMTP handling and authentication in email.go
- Update response handling and error messages for better user experience
- Add constant checks and modify functions based on imageRequest parameters in helper.go
- Use `http.NewRequest` instead of `fmt.Fprint` for improved request handling in relay/channel/common.go
- Update error handling and formatting for better consistency across all files
This commit is contained in:
Laisky.Cai
2024-03-12 06:43:54 +00:00
parent 54203e3d30
commit d953da1ff2
10 changed files with 37 additions and 28 deletions

View File

@@ -5,15 +5,17 @@ import (
"crypto/tls"
"encoding/base64"
"fmt"
"github.com/songquanpeng/one-api/common/config"
"net/smtp"
"strings"
"time"
"github.com/Laisky/errors/v2"
"github.com/songquanpeng/one-api/common/config"
)
func SendEmail(subject string, receiver string, content string) error {
if receiver == "" {
return fmt.Errorf("receiver is empty")
return errors.Errorf("receiver is empty")
}
if config.SMTPFrom == "" { // for compatibility
config.SMTPFrom = config.SMTPAccount