From ff3470085e89e85dd058e9e65991ec24a51cd571 Mon Sep 17 00:00:00 2001 From: Tobias Lindberg Date: Tue, 1 Feb 2022 17:13:07 +0100 Subject: [PATCH] adding 404 for not found endpoints (#144) --- src/webserver.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/webserver.go b/src/webserver.go index f7f4ce9..42114bb 100644 --- a/src/webserver.go +++ b/src/webserver.go @@ -71,6 +71,11 @@ func main() { // gin middleware to enable GZIP support r.Use(gzip.Gzip(gzip.DefaultCompression)) + // set 404 not found page + r.NoRoute(func(c *gin.Context) { + c.JSON(http.StatusNotFound, gin.H{"code": "PAGE_NOT_FOUND", "message": "Page not found"}) + }) + // root endpoint telling API is running r.GET("/", func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"message": "TeslaMateApi container runnnig..", "path": r.BasePath()})