From 451b2ccc9ffda7fd7fad2027b75d93b18ff87cbe Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Tue, 5 Jul 2016 08:43:46 -0700 Subject: [PATCH] Exposed error handlers Signed-off-by: Vishal Rana --- context.go | 2 +- echo.go | 6 +++--- echo_test.go | 2 +- router.go | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/context.go b/context.go index 12bff16c..cf579d96 100644 --- a/context.go +++ b/context.go @@ -508,5 +508,5 @@ func (c *echoContext) Reset(req engine.Request, res engine.Response) { c.context = context.Background() c.request = req c.response = res - c.handler = notFoundHandler + c.handler = NotFoundHandler } diff --git a/echo.go b/echo.go index 4453253c..f66b62aa 100644 --- a/echo.go +++ b/echo.go @@ -209,11 +209,11 @@ var ( // Error handlers var ( - notFoundHandler = func(c Context) error { + NotFoundHandler = func(c Context) error { return ErrNotFound } - methodNotAllowedHandler = func(c Context) error { + MethodNotAllowedHandler = func(c Context) error { return ErrMethodNotAllowed } ) @@ -243,7 +243,7 @@ func (e *Echo) NewContext(req engine.Request, res engine.Response) Context { response: res, echo: e, pvalues: make([]string, *e.maxParam), - handler: notFoundHandler, + handler: NotFoundHandler, } } diff --git a/echo_test.go b/echo_test.go index 1fe48b1e..677fd17b 100644 --- a/echo_test.go +++ b/echo_test.go @@ -129,7 +129,7 @@ func TestEchoMiddlewareError(t *testing.T) { e.Use(WrapMiddleware(func(c Context) error { return errors.New("error") })) - e.GET("/", notFoundHandler) + e.GET("/", NotFoundHandler) c, _ := request(GET, "/", e) assert.Equal(t, http.StatusInternalServerError, c) } diff --git a/router.go b/router.go index 3c5e4a0a..01a0c692 100644 --- a/router.go +++ b/router.go @@ -272,10 +272,10 @@ func (n *node) findHandler(method string) HandlerFunc { func (n *node) checkMethodNotAllowed() HandlerFunc { for _, m := range methods { if h := n.findHandler(m); h != nil { - return methodNotAllowedHandler + return MethodNotAllowedHandler } } - return notFoundHandler + return NotFoundHandler } // Find lookup a handler registed for method and path. It also parses URL for path