Skip to content

Commit

Permalink
Change the response from bad-request to method not allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
hwchiu authored and John-Lin committed Jul 25, 2018
1 parent deebf06 commit b0b2372
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,9 @@ For each Pod, we have fileds need to handle.
- vlanTag: the vlan tag for `ifName` interface.
- ipADdress: the IPv4 address of the `ifName` interface.
- netmask: the IPv4 netmask of the `ifName` interface.

7. restartPolicy: the attribute how the pod restart is container, it should be a string and only valid for those following strings.
- Always,OnFailure,Never

Example:

Request Data:
Expand Down
5 changes: 5 additions & 0 deletions src/net/http/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ func Conflict(req *http.Request, resp http.ResponseWriter, errs ...error) (int,
return WriteStatusAndError(req, resp, http.StatusConflict, errs...)
}

// MethodNotAllow will set the status code http.StatusMethodNotAllowed, to the HTTP response message
func MethodNotAllow(req *http.Request, resp http.ResponseWriter, errs ...error) (int, error) {
return WriteStatusAndError(req, resp, http.StatusMethodNotAllowed, errs...)
}

// UnprocessableEntity will set the status code http.StatusUnprocessableEntity to the HTTP response message
func UnprocessableEntity(req *http.Request, resp http.ResponseWriter, errs ...error) (int, error) {
return WriteStatusAndError(req, resp, http.StatusUnprocessableEntity, errs...)
Expand Down
1 change: 1 addition & 0 deletions src/net/http/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func TestSetStatus(t *testing.T) {
{"InternalServerError", InternalServerError, http.StatusInternalServerError},
{"Conflict", Conflict, http.StatusConflict},
{"UnprocessableEntity", UnprocessableEntity, http.StatusUnprocessableEntity},
{"MethodNotAllow", MethodNotAllow, http.StatusMethodNotAllowed},
}

for _, tc := range testCases {
Expand Down
2 changes: 1 addition & 1 deletion src/server/handler_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func deleteNetworkHandler(ctx *web.Context) {
response.InternalServerError(req.Request, resp.ResponseWriter, err)
return
} else if len(ret) != 0 {
response.BadRequest(req.Request, resp.ResponseWriter, fmt.Errorf("The Network %s still used by some Pods, please close those Pod first", network.Name))
response.MethodNotAllow(req.Request, resp.ResponseWriter, fmt.Errorf("The Network %s still used by some Pods, please close those Pod first", network.Name))
return
}

Expand Down
4 changes: 2 additions & 2 deletions src/server/handler_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (suite *NetworkTestSuite) TestDeleteNetworkFail() {
network entity.Network
errorCode int
}{
{"NetworkNotExis", entity.Network{
{"NetworkDeleteFail", entity.Network{
ID: bson.NewObjectId(),
Type: entity.FakeNetworkType,
Name: namesgenerator.GetRandomName(0),
Expand Down Expand Up @@ -241,7 +241,7 @@ func (suite *NetworkTestSuite) TestDeleteNetworkFail() {
},
},
},
http.StatusBadRequest},
http.StatusMethodNotAllowed},
}

//Create the Pod using the network.
Expand Down

0 comments on commit b0b2372

Please sign in to comment.