Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e530ab2

Browse files
authored
chore: add api specific 404 (#1272)
Prevents weird errors when routes are moved, like #1205
1 parent ba80c79 commit e530ab2

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

coderd/coderd.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func New(options *Options) (http.Handler, func()) {
6969
})
7070

7171
r := chi.NewRouter()
72+
7273
r.Use(
7374
func(next http.Handler) http.Handler {
7475
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -80,6 +81,12 @@ func New(options *Options) (http.Handler, func()) {
8081
)
8182

8283
r.Route("/api/v2", func(r chi.Router) {
84+
r.NotFound(func(rw http.ResponseWriter, r *http.Request) {
85+
httpapi.Write(rw, http.StatusNotFound, httpapi.Response{
86+
Message: "Route not found.",
87+
})
88+
})
89+
8390
r.Use(
8491
// Specific routes can specify smaller limits.
8592
httpmw.RateLimitPerMinute(options.APIRateLimit),

0 commit comments

Comments
 (0)