Skip to content

Commit

Permalink
feat: add custom not found route handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Tibz-Dankan committed Aug 19, 2024
1 parent 41a6d96 commit 7066367
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
17 changes: 17 additions & 0 deletions internal/routes/notFound.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package routes

import (
"net/http"

"github.com/Tibz-Dankan/keep-active/internal/services"
"github.com/gorilla/mux"
)

func notFound(w http.ResponseWriter, r *http.Request) {
message := "Endpoint " + "'" + r.URL.Path + "'" + " does not exist!"
services.AppError(message, 404, w)
}

func NotFoundRoute(router *mux.Router) {
router.NotFoundHandler = http.HandlerFunc(notFound)
}
3 changes: 3 additions & 0 deletions internal/routes/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,8 @@ func AppRouter() *mux.Router {
// Monitor route
monitor.GetMetrics(router)

// Not found route
NotFoundRoute(router)

return router
}

0 comments on commit 7066367

Please sign in to comment.