1
0
mirror of https://github.com/labstack/echo.git synced 2025-01-12 01:22:21 +02:00

Exposed error handlers

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2016-07-05 08:43:46 -07:00
parent c00d017178
commit 451b2ccc9f
4 changed files with 7 additions and 7 deletions

View File

@ -508,5 +508,5 @@ func (c *echoContext) Reset(req engine.Request, res engine.Response) {
c.context = context.Background() c.context = context.Background()
c.request = req c.request = req
c.response = res c.response = res
c.handler = notFoundHandler c.handler = NotFoundHandler
} }

View File

@ -209,11 +209,11 @@ var (
// Error handlers // Error handlers
var ( var (
notFoundHandler = func(c Context) error { NotFoundHandler = func(c Context) error {
return ErrNotFound return ErrNotFound
} }
methodNotAllowedHandler = func(c Context) error { MethodNotAllowedHandler = func(c Context) error {
return ErrMethodNotAllowed return ErrMethodNotAllowed
} }
) )
@ -243,7 +243,7 @@ func (e *Echo) NewContext(req engine.Request, res engine.Response) Context {
response: res, response: res,
echo: e, echo: e,
pvalues: make([]string, *e.maxParam), pvalues: make([]string, *e.maxParam),
handler: notFoundHandler, handler: NotFoundHandler,
} }
} }

View File

@ -129,7 +129,7 @@ func TestEchoMiddlewareError(t *testing.T) {
e.Use(WrapMiddleware(func(c Context) error { e.Use(WrapMiddleware(func(c Context) error {
return errors.New("error") return errors.New("error")
})) }))
e.GET("/", notFoundHandler) e.GET("/", NotFoundHandler)
c, _ := request(GET, "/", e) c, _ := request(GET, "/", e)
assert.Equal(t, http.StatusInternalServerError, c) assert.Equal(t, http.StatusInternalServerError, c)
} }

View File

@ -272,10 +272,10 @@ func (n *node) findHandler(method string) HandlerFunc {
func (n *node) checkMethodNotAllowed() HandlerFunc { func (n *node) checkMethodNotAllowed() HandlerFunc {
for _, m := range methods { for _, m := range methods {
if h := n.findHandler(m); h != nil { 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 // Find lookup a handler registed for method and path. It also parses URL for path