Skip to content

Commit

Permalink
add 400 status code
Browse files Browse the repository at this point in the history
Signed-off-by: lhy1024 <[email protected]>
  • Loading branch information
lhy1024 committed Dec 25, 2024
1 parent 97ad20e commit 79a7508
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/mcs/scheduling/server/apis/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1474,6 +1474,10 @@ func getRegionByID(c *gin.Context) {
c.String(http.StatusBadRequest, err.Error())
return
}
if regionID == 0 {
c.String(http.StatusBadRequest, errs.ErrRegionInvalidID.FastGenByArgs().Error())

Check warning on line 1478 in pkg/mcs/scheduling/server/apis/v1/api.go

View check run for this annotation

Codecov / codecov/patch

pkg/mcs/scheduling/server/apis/v1/api.go#L1477-L1478

Added lines #L1477 - L1478 were not covered by tests
return
}
regionInfo := svr.GetBasicCluster().GetRegion(regionID)
if regionInfo == nil {
c.String(http.StatusNotFound, errs.ErrRegionNotFound.FastGenByArgs(regionID).Error())
Expand Down
4 changes: 4 additions & 0 deletions server/api/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func (h *regionHandler) GetRegionByID(w http.ResponseWriter, r *http.Request) {
h.rd.JSON(w, http.StatusBadRequest, err.Error())
return
}
if regionID == 0 {
h.rd.JSON(w, http.StatusBadRequest, errs.ErrRegionInvalidID.FastGenByArgs())

Check warning on line 69 in server/api/region.go

View check run for this annotation

Codecov / codecov/patch

server/api/region.go#L68-L69

Added lines #L68 - L69 were not covered by tests
return
}

regionInfo := rc.GetRegion(regionID)
if regionInfo == nil {
Expand Down
2 changes: 2 additions & 0 deletions server/api/region_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ func (suite *regionTestSuite) TestRegion() {
re := suite.Require()
mustRegionHeartbeat(re, suite.svr, r)
url := fmt.Sprintf("%s/region/id/%d", suite.urlPrefix, 0)
re.NoError(tu.CheckGetJSON(testDialClient, url, nil, tu.Status(re, http.StatusBadRequest)))
url = fmt.Sprintf("%s/region/id/%d", suite.urlPrefix, 2333)
re.NoError(tu.CheckGetJSON(testDialClient, url, nil, tu.Status(re, http.StatusNotFound)))
url = fmt.Sprintf("%s/region/id/%d", suite.urlPrefix, r.GetID())
r1 := &response.RegionInfo{}
Expand Down
3 changes: 3 additions & 0 deletions tests/integrations/mcs/scheduling/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,9 @@ func (suite *apiTestSuite) checkRegions(cluster *tests.TestCluster) {
err = testutil.ReadGetJSON(re, tests.TestDialClient, urlPrefix, &resp)
re.NoError(err)
re.Equal(3., resp["count"])
urlPrefix = fmt.Sprintf("%s/scheduling/api/v1/regions/0", scheServerAddr)
testutil.CheckGetJSON(tests.TestDialClient, urlPrefix, nil,
testutil.Status(re, http.StatusBadRequest))
urlPrefix = fmt.Sprintf("%s/scheduling/api/v1/regions/233", scheServerAddr)
testutil.CheckGetJSON(tests.TestDialClient, urlPrefix, nil,
testutil.Status(re, http.StatusNotFound), testutil.StringContain(re, "not found"))
Expand Down

0 comments on commit 79a7508

Please sign in to comment.