mirror of
https://github.com/labstack/echo.git
synced 2025-02-13 13:48:25 +02:00
Putting back DefaultHTTPErrorHandler
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
106272e201
commit
5d70ff42fc
36
echo.go
36
echo.go
@ -22,19 +22,20 @@ import (
|
||||
|
||||
type (
|
||||
Echo struct {
|
||||
prefix string
|
||||
middleware []MiddlewareFunc
|
||||
http2 bool
|
||||
maxParam *int
|
||||
httpErrorHandler HTTPErrorHandler
|
||||
binder Binder
|
||||
renderer Renderer
|
||||
pool sync.Pool
|
||||
debug bool
|
||||
hook http.HandlerFunc
|
||||
autoIndex bool
|
||||
logger *log.Logger
|
||||
router *Router
|
||||
prefix string
|
||||
middleware []MiddlewareFunc
|
||||
http2 bool
|
||||
maxParam *int
|
||||
defaultHTTPErrorHandler HTTPErrorHandler
|
||||
httpErrorHandler HTTPErrorHandler
|
||||
binder Binder
|
||||
renderer Renderer
|
||||
pool sync.Pool
|
||||
debug bool
|
||||
hook http.HandlerFunc
|
||||
autoIndex bool
|
||||
logger *log.Logger
|
||||
router *Router
|
||||
}
|
||||
|
||||
Route struct {
|
||||
@ -192,7 +193,7 @@ func New() (e *Echo) {
|
||||
//----------
|
||||
|
||||
e.HTTP2(true)
|
||||
defaultHTTPErrorHandler := func(err error, c *Context) {
|
||||
e.defaultHTTPErrorHandler = func(err error, c *Context) {
|
||||
code := http.StatusInternalServerError
|
||||
msg := http.StatusText(code)
|
||||
if he, ok := err.(*HTTPError); ok {
|
||||
@ -207,7 +208,7 @@ func New() (e *Echo) {
|
||||
}
|
||||
e.logger.Error(err)
|
||||
}
|
||||
e.SetHTTPErrorHandler(defaultHTTPErrorHandler)
|
||||
e.SetHTTPErrorHandler(e.defaultHTTPErrorHandler)
|
||||
e.SetBinder(&binder{})
|
||||
|
||||
// Logger
|
||||
@ -247,6 +248,11 @@ func (e *Echo) HTTP2(on bool) {
|
||||
e.http2 = on
|
||||
}
|
||||
|
||||
// DefaultHTTPErrorHandler invokes the default HTTP error handler.
|
||||
func (e *Echo) DefaultHTTPErrorHandler(err error, c *Context) {
|
||||
e.defaultHTTPErrorHandler(err, c)
|
||||
}
|
||||
|
||||
// SetHTTPErrorHandler registers a custom Echo.HTTPErrorHandler.
|
||||
func (e *Echo) SetHTTPErrorHandler(h HTTPErrorHandler) {
|
||||
e.httpErrorHandler = h
|
||||
|
@ -25,6 +25,9 @@ type (
|
||||
|
||||
func TestEcho(t *testing.T) {
|
||||
e := New()
|
||||
req, _ := http.NewRequest(GET, "/", nil)
|
||||
rec := httptest.NewRecorder()
|
||||
c := NewContext(req, NewResponse(rec, e), e)
|
||||
|
||||
// Router
|
||||
assert.NotNil(t, e.Router())
|
||||
@ -32,6 +35,10 @@ func TestEcho(t *testing.T) {
|
||||
// Debug
|
||||
e.SetDebug(true)
|
||||
assert.True(t, e.debug)
|
||||
|
||||
// DefaultHTTPErrorHandler
|
||||
e.DefaultHTTPErrorHandler(errors.New("error"), c)
|
||||
assert.Equal(t, http.StatusInternalServerError, rec.Code)
|
||||
}
|
||||
|
||||
func TestEchoIndex(t *testing.T) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user