mirror of
https://github.com/labstack/echo.git
synced 2024-12-22 20:06:21 +02:00
Fixed default http handler
Signed-off-by: Vishal Rana <vishal.rana@verizon.com>
This commit is contained in:
parent
bb0735bbc5
commit
fd5f48a884
62
echo.go
62
echo.go
@ -51,20 +51,19 @@ import (
|
||||
type (
|
||||
// Echo is the top-level framework instance.
|
||||
Echo struct {
|
||||
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 Logger
|
||||
router *Router
|
||||
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 Logger
|
||||
router *Router
|
||||
}
|
||||
|
||||
// Logger is the interface that declares echo's logging system.
|
||||
@ -241,22 +240,7 @@ func New() (e *Echo) {
|
||||
//----------
|
||||
|
||||
e.HTTP2(true)
|
||||
e.defaultHTTPErrorHandler = func(err error, c *Context) {
|
||||
code := http.StatusInternalServerError
|
||||
msg := http.StatusText(code)
|
||||
if he, ok := err.(*HTTPError); ok {
|
||||
code = he.code
|
||||
msg = he.message
|
||||
}
|
||||
if e.debug {
|
||||
msg = err.Error()
|
||||
}
|
||||
if !c.response.committed {
|
||||
http.Error(c.response, msg, code)
|
||||
}
|
||||
e.logger.Error(err)
|
||||
}
|
||||
e.SetHTTPErrorHandler(e.defaultHTTPErrorHandler)
|
||||
e.SetHTTPErrorHandler(e.DefaultHTTPErrorHandler)
|
||||
e.SetBinder(&binder{})
|
||||
|
||||
// Logger
|
||||
@ -287,7 +271,19 @@ func (e *Echo) HTTP2(on bool) {
|
||||
|
||||
// DefaultHTTPErrorHandler invokes the default HTTP error handler.
|
||||
func (e *Echo) DefaultHTTPErrorHandler(err error, c *Context) {
|
||||
e.defaultHTTPErrorHandler(err, c)
|
||||
code := http.StatusInternalServerError
|
||||
msg := http.StatusText(code)
|
||||
if he, ok := err.(*HTTPError); ok {
|
||||
code = he.code
|
||||
msg = he.message
|
||||
}
|
||||
if e.debug {
|
||||
msg = err.Error()
|
||||
}
|
||||
if !c.response.committed {
|
||||
http.Error(c.response, msg, code)
|
||||
}
|
||||
e.logger.Error(err)
|
||||
}
|
||||
|
||||
// SetHTTPErrorHandler registers a custom Echo.HTTPErrorHandler.
|
||||
@ -595,8 +591,8 @@ func (e *Echo) Run(addr string) {
|
||||
}
|
||||
|
||||
// RunTLS runs a server with TLS configuration.
|
||||
func (e *Echo) RunTLS(addr, crtFile, keyFile string) {
|
||||
e.run(e.Server(addr), crtFile, keyFile)
|
||||
func (e *Echo) RunTLS(addr, certfile, keyfile string) {
|
||||
e.run(e.Server(addr), certfile, keyfile)
|
||||
}
|
||||
|
||||
// RunServer runs a custom server.
|
||||
|
Loading…
Reference in New Issue
Block a user