diff --git a/httpr.go b/httpr.go index e9b995d..a67e232 100644 --- a/httpr.go +++ b/httpr.go @@ -133,13 +133,13 @@ func New() *Router { func (rr *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) { if tree, ok := rr.tree[r.Method]; ok { - if r.URL.Path[0] != '/' { - panic("first element of path should be a slash (/) symbol") + path, err := newPath(r.URL.Path) + if err != nil { + http.Error(w, err.Error(), http.StatusNotAcceptable) + return } - path, _ := newPath(r.URL.Path) - - if handler, params := tree.get(path, 0); handler != nil { + if handler, params := tree.get(path); handler != nil { if params != nil { r = r.WithContext(context.WithValue(r.Context(), ParamsKey, params)) }