Renamed controllers package to routes.
This commit is contained in:
parent
60dedc0944
commit
869c507737
11 changed files with 12 additions and 12 deletions
40
routes/error.go
Normal file
40
routes/error.go
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
package routes
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"goweb/controller"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
type Error struct {
|
||||
controller.Controller
|
||||
}
|
||||
|
||||
func (e *Error) Get(err error, c echo.Context) {
|
||||
if c.Response().Committed {
|
||||
return
|
||||
}
|
||||
|
||||
code := http.StatusInternalServerError
|
||||
if he, ok := err.(*echo.HTTPError); ok {
|
||||
code = he.Code
|
||||
}
|
||||
|
||||
if code >= 500 {
|
||||
c.Logger().Error(err)
|
||||
} else {
|
||||
c.Logger().Info(err)
|
||||
}
|
||||
|
||||
p := controller.NewPage(c)
|
||||
p.Layout = "main"
|
||||
p.Title = http.StatusText(code)
|
||||
p.Name = "error"
|
||||
p.StatusCode = code
|
||||
|
||||
if err = e.RenderPage(c, p); err != nil {
|
||||
c.Logger().Error(err)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue