Skip to content

Commit 5781578

Browse files
committed
Handle empty body in TestDataSourceConnection
Update TestDataSourceConnection to support requests with an empty body by loading the existing data source config if available. Returns 404 if the data source is not found, otherwise proceeds as before.
1 parent c1f7845 commit 5781578

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

api/handlers/datasource.go

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package handlers
22

33
import (
4-
"context"
5-
"fmt"
6-
"log"
7-
"net/http"
8-
"time"
9-
10-
"github.com/gin-gonic/gin"
11-
"github.com/hhftechnology/middleware-manager/models"
12-
"github.com/hhftechnology/middleware-manager/services"
4+
"context"
5+
"fmt"
6+
"log"
7+
"net/http"
8+
"time"
9+
10+
"github.com/gin-gonic/gin"
11+
"github.com/hhftechnology/middleware-manager/models"
12+
"github.com/hhftechnology/middleware-manager/services"
1313
)
1414

1515
// DataSourceHandler handles data source configuration requests
@@ -117,8 +117,19 @@ func (h *DataSourceHandler) TestDataSourceConnection(c *gin.Context) {
117117

118118
var config models.DataSourceConfig
119119
if err := c.ShouldBindJSON(&config); err != nil {
120-
ResponseWithError(c, http.StatusBadRequest, fmt.Sprintf("Invalid request: %v", err))
121-
return
120+
if err.Error() == "EOF" {
121+
// Request body is empty, try to get existing config
122+
sources := h.ConfigManager.GetDataSources()
123+
if source, ok := sources[name]; ok {
124+
config = source
125+
} else {
126+
ResponseWithError(c, http.StatusNotFound, fmt.Sprintf("Data source '%s' not found", name))
127+
return
128+
}
129+
} else {
130+
ResponseWithError(c, http.StatusBadRequest, fmt.Sprintf("Invalid request: %v", err))
131+
return
132+
}
122133
}
123134

124135
// Create a context with timeout

0 commit comments

Comments
 (0)