Skip to content

Commit

Permalink
400 for a not found instead of 500 + test
Browse files Browse the repository at this point in the history
  • Loading branch information
kayra1 committed Apr 18, 2024
1 parent 82ab3d6 commit ec1c385
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ func DeleteCertificateRequest(env *Environment) http.HandlerFunc {
id := r.PathValue("id")
insertId, err := env.DB.Delete(id)
if err != nil {
if err.Error() == "csr id not found" {
logError(err.Error(), http.StatusBadRequest, w)
return
}
logError(err.Error(), http.StatusInternalServerError, w)
return
}
Expand Down
8 changes: 8 additions & 0 deletions internal/api/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ func TestGoCertRouter(t *testing.T) {
response: "1",
status: http.StatusAccepted,
},
{
desc: "delete csr5 fail",
method: "DELETE",
path: "/api/v1/certificate_requests/5",
data: "",
response: "error: csr id not found",
status: http.StatusBadRequest,
},
{
desc: "get csr1 fail",
method: "GET",
Expand Down

0 comments on commit ec1c385

Please sign in to comment.