1
0
mirror of https://github.com/labstack/echo.git synced 2025-01-07 23:01:56 +02:00

Fixed default http handler

Signed-off-by: Vishal Rana <vishal.rana@verizon.com>
This commit is contained in:
Vishal Rana 2016-02-08 22:15:38 -08:00 committed by Vishal Rana
parent bb0735bbc5
commit fd5f48a884

62
echo.go
View File

@ -51,20 +51,19 @@ import (
type ( type (
// Echo is the top-level framework instance. // Echo is the top-level framework instance.
Echo struct { Echo struct {
prefix string prefix string
middleware []MiddlewareFunc middleware []MiddlewareFunc
http2 bool http2 bool
maxParam *int maxParam *int
defaultHTTPErrorHandler HTTPErrorHandler httpErrorHandler HTTPErrorHandler
httpErrorHandler HTTPErrorHandler binder Binder
binder Binder renderer Renderer
renderer Renderer pool sync.Pool
pool sync.Pool debug bool
debug bool hook http.HandlerFunc
hook http.HandlerFunc autoIndex bool
autoIndex bool logger Logger
logger Logger router *Router
router *Router
} }
// Logger is the interface that declares echo's logging system. // Logger is the interface that declares echo's logging system.
@ -241,22 +240,7 @@ func New() (e *Echo) {
//---------- //----------
e.HTTP2(true) e.HTTP2(true)
e.defaultHTTPErrorHandler = func(err error, c *Context) { e.SetHTTPErrorHandler(e.DefaultHTTPErrorHandler)
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.SetBinder(&binder{}) e.SetBinder(&binder{})
// Logger // Logger
@ -287,7 +271,19 @@ func (e *Echo) HTTP2(on bool) {
// DefaultHTTPErrorHandler invokes the default HTTP error handler. // DefaultHTTPErrorHandler invokes the default HTTP error handler.
func (e *Echo) DefaultHTTPErrorHandler(err error, c *Context) { 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. // SetHTTPErrorHandler registers a custom Echo.HTTPErrorHandler.
@ -595,8 +591,8 @@ func (e *Echo) Run(addr string) {
} }
// RunTLS runs a server with TLS configuration. // RunTLS runs a server with TLS configuration.
func (e *Echo) RunTLS(addr, crtFile, keyFile string) { func (e *Echo) RunTLS(addr, certfile, keyfile string) {
e.run(e.Server(addr), crtFile, keyFile) e.run(e.Server(addr), certfile, keyfile)
} }
// RunServer runs a custom server. // RunServer runs a custom server.