Skip to content

Commit 105343c

Browse files
committed
handle handler error
1 parent 7f3595b commit 105343c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

router.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,19 @@ func (r *Router) add(method, path string, handlers []Handler) {
4444
}
4545

4646
func (r *Router) find(method, path string) []Handler {
47-
routes := r.routes[method]
47+
routes, ok := r.routes[method]
48+
if !ok {
49+
return nil
50+
}
51+
4852
for _, route := range routes {
4953
if matches, params := route.match(path); matches {
5054
c := NewContext(nil, nil)
5155
c.params = params
5256
return r.applyMiddleware(route.Handlers, method)
5357
}
5458
}
59+
5560
return nil
5661
}
5762

@@ -74,7 +79,7 @@ func RouterHandler(router *Router) func(ctx *fasthttp.RequestCtx) {
7479
method := string(ctx.Method())
7580
handlers := router.find(method, path)
7681
if handlers == nil {
77-
ctx.Error("Not found", fasthttp.StatusNotFound)
82+
ctx.Error("Page not found", fasthttp.StatusNotFound)
7883
return
7984
}
8085

0 commit comments

Comments
 (0)