aboutsummaryrefslogtreecommitdiff
path: root/pkg/handler/error.go
diff options
context:
space:
mode:
authorAlexander Neonxp Kiryukhin <i@neonxp.ru>2024-10-07 03:45:49 +0300
committerAlexander Neonxp Kiryukhin <i@neonxp.ru>2024-10-07 03:47:56 +0300
commitffcc9eeb1746971d7d009822ae65a1201c54e289 (patch)
treed8d347f638f5d98c83db36f9dcb2b45c569b03fc /pkg/handler/error.go
parent420e049415c8ec7f7a209a03110eecbe0c83e9e0 (diff)
Мелкие правки админки
Diffstat (limited to 'pkg/handler/error.go')
-rw-r--r--pkg/handler/error.go35
1 files changed, 34 insertions, 1 deletions
diff --git a/pkg/handler/error.go b/pkg/handler/error.go
index f74be59..b1bfd51 100644
--- a/pkg/handler/error.go
+++ b/pkg/handler/error.go
@@ -2,13 +2,46 @@ package handler
import (
"log"
+ "net/http"
"github.com/labstack/echo/v4"
"sh.org.ru/pkg/tpl"
)
func ErrorHandler(err error, c echo.Context) {
- if err := tpl.ErrorPage(err.Error()).Render(c.Request().Context(), c.Response()); err != nil {
+ if c.Response().Committed {
+ return
+ }
+
+ he, ok := err.(*echo.HTTPError)
+ if ok {
+ if he.Internal != nil {
+ if herr, ok := he.Internal.(*echo.HTTPError); ok {
+ he = herr
+ }
+ }
+ } else {
+ he = &echo.HTTPError{
+ Code: http.StatusInternalServerError,
+ Message: http.StatusText(http.StatusInternalServerError),
+ }
+ }
+ code := he.Code
+ message, ok := he.Message.(string)
+ if !ok {
+ message = "Неизвестная ошибка"
+ }
+
+ // Send response
+ if c.Request().Method == http.MethodHead { // Issue #608
+ err = c.NoContent(he.Code)
+ } else {
+ c.Response().WriteHeader(code)
+ if err := tpl.ErrorPage(code, message).Render(c.Request().Context(), c.Response()); err != nil {
+ log.Println(err)
+ }
+ }
+ if err != nil {
log.Println(err)
}
}