Skip to content

Commit

Permalink
added 404 handling
Browse files Browse the repository at this point in the history
  • Loading branch information
karnthis committed Sep 26, 2023
1 parent ea483c7 commit a48bab9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions japicore/miscRouteHandling.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ func Handler() bunrouter.HandlerFunc {
}
}

func RouteNotFoundHandler() bunrouter.HandlerFunc {
return func(w http.ResponseWriter, req bunrouter.Request) error {
warning := fmt.Sprintf("%s is not an availble route", req.URL.Path)
return jutils.ProcessCustomHttpError("MethodNotAllowedHandler", warning, 404, w)
}
}

func MethodNotAllowedHandler() bunrouter.HandlerFunc {
return func(w http.ResponseWriter, req bunrouter.Request) error {
warning := fmt.Sprintf("%s method not availble for \"%s\"", req.URL.Path, req.Method)
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func main() {

router := bunrouter.New(
bunrouter.WithMethodNotAllowedHandler(japicore.MethodNotAllowedHandler()),
bunrouter.WithNotFoundHandler(japicore.RouteNotFoundHandler()),
)
group := router.NewGroup("")

Expand Down

0 comments on commit a48bab9

Please sign in to comment.