feat(storage): improve storage connectivity error handling and multi-instance support

Enhance error messaging for storage connectivity issues by sanitizing raw errors to prevent leaking sensitive information. Introduce a new utility function for consistent error handling across storage backend operations. Additionally, implement logic to support multi-instance storage backends, allowing for more flexible workspace configurations and improved reporting of active storage providers.
This commit is contained in:
wizardchen
2026-07-15 14:36:26 +08:00
committed by lyingbug
parent 6349fff002
commit a8dea5f9a3
8 changed files with 208 additions and 42 deletions
+15 -2
View File
@@ -1,6 +1,7 @@
package handler
import (
"errors"
"net/http"
apperrors "github.com/Tencent/WeKnora/internal/errors"
@@ -10,6 +11,18 @@ import (
"github.com/gin-gonic/gin"
)
// storageTestErrorMessage returns a safe user-facing message for a storage
// connectivity test failure. Validation/AppError messages are already
// user-facing and are passed through, while raw driver/network errors are
// sanitized so they don't leak internal hostnames, IPs, ports or TLS details.
func storageTestErrorMessage(err error) string {
var appErr *apperrors.AppError
if errors.As(err, &appErr) {
return appErr.Message
}
return sanitizeStorageCheckError(err)
}
type StorageBackendHandler struct {
repo interfaces.StorageBackendRepository
service interfaces.StorageBackendService
@@ -121,7 +134,7 @@ func (h *StorageBackendHandler) TestRaw(c *gin.Context) {
return
}
if err := h.service.Test(c.Request.Context(), backend); err != nil {
c.JSON(http.StatusOK, gin.H{"success": false, "error": err.Error()})
c.JSON(http.StatusOK, gin.H{"success": false, "error": storageTestErrorMessage(err)})
return
}
c.JSON(http.StatusOK, gin.H{"success": true})
@@ -138,7 +151,7 @@ func (h *StorageBackendHandler) TestByID(c *gin.Context) {
return
}
if err := h.service.Test(c.Request.Context(), backend); err != nil {
c.JSON(http.StatusOK, gin.H{"success": false, "error": err.Error()})
c.JSON(http.StatusOK, gin.H{"success": false, "error": storageTestErrorMessage(err)})
return
}
c.JSON(http.StatusOK, gin.H{"success": true})