Skip to content

Commit e327850

Browse files
authored
return 404 when no matching route is found (#1067)
* return 404 when a matching route is not found * update other middleware and tests
1 parent fc2cbe9 commit e327850

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

oapi_validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func ValidateRequestFromContext(ctx echo.Context, router routers.Router, options
119119
case *routers.RouteError:
120120
// We've got a bad request, the path requested doesn't match
121121
// either server, or path, or something.
122-
return echo.NewHTTPError(http.StatusBadRequest, e.Reason)
122+
return echo.NewHTTPError(http.StatusNotFound, e.Reason)
123123
default:
124124
// This should never happen today, but if our upstream code changes,
125125
// we don't want to crash the server, so handle the unexpected error.

oapi_validate_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ func TestOapiRequestValidator(t *testing.T) {
102102
called = true
103103
return nil
104104
})
105-
// Let's send the request to the wrong server, this should fail validation
105+
// Let's send the request to the wrong server, this should return 404
106106
{
107107
rec := doGet(t, e, "http://not.deepmap.ai/resource")
108-
assert.Equal(t, http.StatusBadRequest, rec.Code)
108+
assert.Equal(t, http.StatusNotFound, rec.Code)
109109
assert.False(t, called, "Handler should not have been called")
110110
}
111111

0 commit comments

Comments
 (0)