Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

Return more readable error message when ping mysql fails

天舟af9480420211
diff --git a/server/sql.go b/server/sql.go
index 080f26767d..97b9d6418c 100644
--- a/server/sql.go
+++ b/server/sql.go
@@ -27,7 +27,15 @@ func (s *Server) registerSqlRoutes(g *echo.Group) {
Port: connectionInfo.Port,
})
if err != nil {
- return echo.NewHTTPError(http.StatusBadRequest, "Failed to open database").SetInternal(err)
+ usePassword := "YES"
+ if connectionInfo.Password == "" {
+ usePassword = "NO"
+ }
+ hostPort := connectionInfo.Host
+ if connectionInfo.Port != "" {
+ hostPort += ":" + connectionInfo.Port
+ }
+ return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Failed to connect %s for user '%s' (using password: %s)", hostPort, connectionInfo.Username, usePassword)).SetInternal(err)
}
resultSet := &api.SqlResultSet{}