minio connection log
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
package ai_summarizer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
@@ -29,3 +32,55 @@ func isMinioNotFound(err error) bool {
|
||||
strings.Contains(msg, "nosuchkey") ||
|
||||
strings.Contains(msg, "not found")
|
||||
}
|
||||
|
||||
// isMinioConnectionError reports whether err indicates MinIO is unreachable.
|
||||
func isMinioConnectionError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
if errors.Is(err, ErrMinIOUnavailable) {
|
||||
return true
|
||||
}
|
||||
if errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled) {
|
||||
return true
|
||||
}
|
||||
var netErr net.Error
|
||||
if errors.As(err, &netErr) && netErr.Timeout() {
|
||||
return true
|
||||
}
|
||||
var opErr *net.OpError
|
||||
if errors.As(err, &opErr) {
|
||||
return true
|
||||
}
|
||||
msg := strings.ToLower(err.Error())
|
||||
connectionHints := []string{
|
||||
"connection refused",
|
||||
"connection reset",
|
||||
"no such host",
|
||||
"dial tcp",
|
||||
"dial udp",
|
||||
"i/o timeout",
|
||||
"network is unreachable",
|
||||
"broken pipe",
|
||||
"tls handshake",
|
||||
"server gave http response to https client",
|
||||
"eof",
|
||||
}
|
||||
for _, hint := range connectionHints {
|
||||
if strings.Contains(msg, hint) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// wrapMinIOError attaches ErrMinIOUnavailable when the root cause is connectivity.
|
||||
func wrapMinIOError(err error) error {
|
||||
if err == nil || isMinioNotFound(err) {
|
||||
return err
|
||||
}
|
||||
if isMinioConnectionError(err) {
|
||||
return fmt.Errorf("%w: %v", ErrMinIOUnavailable, err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user