Skip to content

Commit 4926fa8

Browse files
committed
fix: return JSON error object instead of plain string for HTTP 405 responses
1 parent 65e41fe commit 4926fa8

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

pkg/router/router.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
docs "github.com/envelope-zero/backend/api"
1111
"github.com/envelope-zero/backend/pkg/controllers"
12+
"github.com/envelope-zero/backend/pkg/httperrors"
1213
"github.com/envelope-zero/backend/pkg/httputil"
1314
"github.com/gin-contrib/cors"
1415
"github.com/gin-contrib/logger"
@@ -39,6 +40,9 @@ func Config() (*gin.Engine, error) {
3940
r.Use(gin.Recovery())
4041
r.Use(requestid.New())
4142
r.Use(URLMiddleware())
43+
r.NoMethod(func(c *gin.Context) {
44+
httperrors.New(c, http.StatusMethodNotAllowed, "This HTTP method is not allowed for the endpoint you called")
45+
})
4246
r.Use(logger.SetLogger(
4347
logger.WithDefaultLevel(zerolog.InfoLevel),
4448
logger.WithClientErrorLevel(zerolog.InfoLevel),

0 commit comments

Comments
 (0)