@@ -642,8 +642,9 @@ func TestMustJWTWithConfig_SuccessHandler(t *testing.T) {
642642 ParseTokenFunc : func (c * echo.Context , auth string ) (interface {}, error ) {
643643 return auth , nil
644644 },
645- SuccessHandler : func (c * echo.Context ) {
645+ SuccessHandler : func (c * echo.Context ) error {
646646 c .Set ("success" , "yes" )
647+ return nil
647648 },
648649 }.ToMiddleware ()
649650 assert .NoError (t , err )
@@ -658,6 +659,33 @@ func TestMustJWTWithConfig_SuccessHandler(t *testing.T) {
658659 assert .Equal (t , http .StatusTeapot , res .Code )
659660}
660661
662+ func TestMustJWTWithConfig_SuccessHandlerError (t * testing.T ) {
663+ e := echo .New ()
664+
665+ e .GET ("/" , func (c * echo.Context ) error {
666+ return c .String (http .StatusTeapot , "should not end up here" )
667+ })
668+
669+ mw , err := Config {
670+ ParseTokenFunc : func (c * echo.Context , auth string ) (interface {}, error ) {
671+ return auth , nil
672+ },
673+ SuccessHandler : func (c * echo.Context ) error {
674+ return echo .ErrForbidden .Wrap (errors .New ("nope" ))
675+ },
676+ }.ToMiddleware ()
677+ assert .NoError (t , err )
678+ e .Use (mw )
679+
680+ req := httptest .NewRequest (http .MethodGet , "/" , nil )
681+ req .Header .Add (echo .HeaderAuthorization , "Bearer valid_token_base64" )
682+ res := httptest .NewRecorder ()
683+ e .ServeHTTP (res , req )
684+
685+ assert .Equal (t , "{\" message\" :\" Forbidden\" }\n " , res .Body .String ())
686+ assert .Equal (t , http .StatusForbidden , res .Code )
687+ }
688+
661689func TestJWTWithConfig_ContinueOnIgnoredError (t * testing.T ) {
662690 var testCases = []struct {
663691 name string
0 commit comments