Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The 'RouteNotFound' have a bug #2401

Closed
3 tasks
deatil opened this issue Feb 18, 2023 · 4 comments · Fixed by #2411
Closed
3 tasks

The 'RouteNotFound' have a bug #2401

deatil opened this issue Feb 18, 2023 · 4 comments · Fixed by #2411

Comments

@deatil
Copy link

deatil commented Feb 18, 2023

Issue Description

Checklist

  • Dependencies installed
  • No typos
  • Searched existing issues and docs

Expected behaviour

Actual behaviour

Steps to reproduce

Working code to debug

package main

import "github.com/labstack/echo/v4"

func main() {
  e := echo.New()
  e.HTTPErrorHandler = HTTPErrorHandler
  
  e.GET("/test1", test1Handler)
  e.GET("/test2", test2Handler)
  e.RouteNotFound("/*", indexHandler)
  
  g := e.Group("/admin")
  g.GET("/test1", adminTest1Handler)
  g.GET("/test2", adminTest2Handler)
  g.RouteNotFound("/*", adminIndexHandler)
}

Version/commit

Get path /test3 and will goto indexHandler, bug get /admin/test3 goto HTTPErrorHandler. The /admin/test3 goto adminIndexHandler is right.

The echo code have some test, but the bug is not checked.

@aldas
Copy link
Contributor

aldas commented Feb 18, 2023

Hi, I am unable to recreate it. Could you edit my example:

func main() {
	e := echo.New()
	e.HTTPErrorHandler = func(err error, c echo.Context) {
		log.Printf("--- inside global error handler!\n")
		e.DefaultHTTPErrorHandler(err, c)
	}

	e.GET("/test1", hello)
	e.GET("/test2", hello)
	e.RouteNotFound("/*", indexHandler)

	g := e.Group("/admin")
	g.GET("/test1", hello)
	g.GET("/test2", hello)
	g.RouteNotFound("/*", adminIndexHandler)

	if err := e.Start(":8080"); !errors.Is(err, http.ErrServerClosed) {
		log.Fatal(err)
	}
}

func hello(c echo.Context) error {
	log.Printf("=== inside hello handler!\n")
	return c.String(http.StatusOK, "hello!")
}

func indexHandler(c echo.Context) error {
	log.Printf("+++ inside indexHandler handler!\n")
	return c.String(http.StatusOK, "indexHandler!")
}

func adminIndexHandler(c echo.Context) error {
	log.Printf("--- inside adminIndexHandler handler!\n")
	return c.String(http.StatusOK, "adminIndexHandler!")
	// if this functions returns an error the `e.HTTPErrorHandler` fill handle it
}

I test with curl -v http://localhost:8080/admin/test3

Output:

x@x:~/codet$ curl -v http://localhost:8080/admin/test3 
*   Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /admin/test3 HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.85.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Type: text/plain; charset=UTF-8
< Date: Sat, 18 Feb 2023 16:26:41 GMT
< Content-Length: 18
< 
* Connection #0 to host localhost left intact
adminIndexHandler!

@deatil
Copy link
Author

deatil commented Feb 19, 2023

@aldas hi, i test and find the bug.

When use g.Use(middle) and it will goto errorhandler.

@deatil
Copy link
Author

deatil commented Feb 24, 2023

@aldas hi,i test and the bug is come when have a middle. example: g.Use(middle) or g := e.Group("/admin", middle). these are going to errorhandler.

@aldas
Copy link
Contributor

aldas commented Feb 24, 2023

This will be fixed with #2411

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants