mirror of
https://github.com/labstack/echo.git
synced 2024-12-24 20:14:31 +02:00
Exposed error handlers
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
c00d017178
commit
451b2ccc9f
@ -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
|
||||
}
|
||||
|
6
echo.go
6
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,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user