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

feat: Add a new ErrorHandlerWithContext #1328

Merged
merged 2 commits into from
Jun 13, 2019
Merged

Conversation

tomscholz
Copy link
Contributor

@tomscholz tomscholz commented May 2, 2019

This commit adds a new error handler, which is passed the
current context, so that you can add custom redirects or even
other kinds of responses. For example:

e.Use(middleware.JWTWithConfig(middleware.JWTConfig{
	SigningKey: []byte("secret"),
	TokenLookup: "query:token",
	ErrorHandlerWithContext: func(err error, c echo.Context) error {
		// do stuff with context and err
		switch err.(type) {
		case jwt.ValidationError:
			return c.Redirect(http.StatusSeeOther, "/login")
		}
		return err
	},
}))

What needs to be done, to get this merged?

This commit adds a new error handler, which is passed the 
current context, so that you can add custom redirects or even
other kinds of responses. For example:

```go
	e.Use(middleware.JWTWithConfig(middleware.JWTConfig{
		SigningKey: []byte("secret"),
		TokenLookup: "query:token",
		ErrorHandlerWithContext: func(err error, c echo.Context) error {
			// do stuff with context and err
			switch err.(type) {
			case jwt.ValidationError:
				return c.Redirect(http.StatusSeeOther, "/login")
			}
			return err
		},
	}))
```
@tomscholz
Copy link
Contributor Author

It seems like the build is failing because the script ran into some ratelimiter of the googleapi. If someone with access to the travis-ci project could retrigger the build. That would be neat!

@tomscholz
Copy link
Contributor Author

Bump

@vishr
Copy link
Member

vishr commented Jun 10, 2019

@tomscholz Can this be achieved via a custom http handler?

@TomLiu-GitHub
Copy link

Somebody seems to think the same as me.

@vishr
Copy link
Member

vishr commented Jun 12, 2019

@TomLiu-GitHub, @tomscholz I can understand the sentiment but if you look at this change, it should/can be applied to all the middleware, isn't it?

@horrorhorst
Copy link

horrorhorst commented Jun 12, 2019

@vishr after a quick look I don't see this change necessary for all middlewares, but if the middleware has an option for a custom error handler, it can be useful and should be evaluated

@vishr
Copy link
Member

vishr commented Jun 13, 2019

For v5, I would like this to be merged with JWTErrorHandler.

@vishr vishr merged commit 3136157 into labstack:master Jun 13, 2019
@vishr vishr mentioned this pull request Jun 13, 2019
@tomscholz tomscholz deleted the patch-1 branch December 3, 2021 17:34
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 this pull request may close these issues.

4 participants