diff --git a/internal/routes/notFound.go b/internal/routes/notFound.go new file mode 100644 index 0000000..3b3660f --- /dev/null +++ b/internal/routes/notFound.go @@ -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) +} diff --git a/internal/routes/router.go b/internal/routes/router.go index 4c534f0..276ccf7 100644 --- a/internal/routes/router.go +++ b/internal/routes/router.go @@ -73,5 +73,8 @@ func AppRouter() *mux.Router { // Monitor route monitor.GetMetrics(router) + // Not found route + NotFoundRoute(router) + return router }