updated hws.ThrowError to not return an error and log it to console instead

fixed errors_test

fixed tests
This commit is contained in:
2026-02-03 18:11:17 +11:00
parent 95a17597cf
commit 563908bbb4
14 changed files with 249 additions and 239 deletions

View File

@@ -30,13 +30,13 @@ const (
MethodPATCH Method = "PATCH"
)
// Server.AddRoutes registers the page handlers for the server.
// AddRoutes registers the page handlers for the server.
// At least one route must be provided.
// If any route patterns (path + method) are defined multiple times, the first
// instance will be added and any additional conflicts will be discarded.
func (server *Server) AddRoutes(routes ...Route) error {
func (s *Server) AddRoutes(routes ...Route) error {
if len(routes) == 0 {
return errors.New("No routes provided")
return errors.New("no routes provided")
}
patterns := []string{}
mux := http.NewServeMux()
@@ -47,10 +47,10 @@ func (server *Server) AddRoutes(routes ...Route) error {
}
for _, method := range route.Methods {
if !validMethod(method) {
return fmt.Errorf("Invalid method %s for path %s", method, route.Path)
return fmt.Errorf("invalid method %s for path %s", method, route.Path)
}
if route.Handler == nil {
return fmt.Errorf("No handler provided for %s %s", method, route.Path)
return fmt.Errorf("no handler provided for %s %s", method, route.Path)
}
pattern := fmt.Sprintf("%s %s", method, route.Path)
if slices.Contains(patterns, pattern) {
@@ -61,8 +61,8 @@ func (server *Server) AddRoutes(routes ...Route) error {
}
}
server.server.Handler = mux
server.routes = true
s.server.Handler = mux
s.routes = true
return nil
}