Files
drip/internal/shared/utils/errors.go
zhiqing 307cf8e6cc feat: Add Bearer Token authentication support and optimize code structure
- Add Bearer Token authentication, supporting tunnel access control via the --auth-bearer parameter
- Refactor large modules into smaller, more focused components to improve code maintainability
- Update dependency versions, including golang.org/x/crypto, golang.org/x/net, etc.
- Add SilenceUsage and SilenceErrors configuration for all CLI commands
- Modify connector configuration structure to support the new authentication method
- Update recent change log in README with new feature descriptions

BREAKING CHANGE: Authentication via Bearer Token is now supported, requiring the new --auth-bearer parameter
2026-01-29 14:40:53 +08:00

36 lines
1.3 KiB
Go

package utils
import "strings"
// IsNetworkError checks if an error message indicates a common network error
// that should be handled gracefully (not logged as severe errors).
func IsNetworkError(errStr string) bool {
return strings.Contains(errStr, "EOF") ||
strings.Contains(errStr, "connection reset by peer") ||
strings.Contains(errStr, "broken pipe") ||
strings.Contains(errStr, "connection refused") ||
strings.Contains(errStr, "use of closed network connection") ||
strings.Contains(errStr, "websocket: close")
}
// IsProtocolError checks if an error message indicates a protocol-level error
// (invalid requests, malformed data, etc.).
func IsProtocolError(errStr string) bool {
return strings.Contains(errStr, "payload too large") ||
strings.Contains(errStr, "failed to read registration frame") ||
strings.Contains(errStr, "expected register frame") ||
strings.Contains(errStr, "failed to parse registration request") ||
strings.Contains(errStr, "failed to parse HTTP request") ||
strings.Contains(errStr, "tunnel type not allowed")
}
// ContainsAny checks if a string contains any of the given substrings.
func ContainsAny(s string, substrings ...string) bool {
for _, substr := range substrings {
if strings.Contains(s, substr) {
return true
}
}
return false
}