2023-05-20 20:15:57 +02:00
|
|
|
// Copyright 2023 wanderer <a_mirre at utb dot cz>
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2023-04-21 12:33:14 +02:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
2023-05-30 23:50:37 +02:00
|
|
|
"errors"
|
2023-04-21 12:33:14 +02:00
|
|
|
"fmt"
|
|
|
|
"strconv"
|
2023-05-06 21:50:35 +02:00
|
|
|
|
2023-08-24 18:43:24 +02:00
|
|
|
moduser "git.dotya.ml/mirre-mt/pcmt/modules/user"
|
2023-05-06 21:50:35 +02:00
|
|
|
"github.com/labstack/echo/v4"
|
2023-04-21 12:33:14 +02:00
|
|
|
)
|
|
|
|
|
2023-05-30 23:50:37 +02:00
|
|
|
var (
|
|
|
|
ErrNoSession = errors.New("No session found, please log in")
|
|
|
|
ErrSessionExpired = errors.New("Session expired, log in again")
|
|
|
|
)
|
|
|
|
|
2023-05-06 21:50:35 +02:00
|
|
|
func renderErrorPage(c echo.Context, status int, statusText, error string) error {
|
2023-05-11 23:50:40 +02:00
|
|
|
addHeaders(c)
|
|
|
|
|
2023-04-21 12:33:14 +02:00
|
|
|
strStatus := strconv.Itoa(status)
|
|
|
|
|
2023-08-24 18:43:24 +02:00
|
|
|
p := newPage()
|
|
|
|
|
|
|
|
p.Title = fmt.Sprintf("Error %s - %s", strStatus, statusText)
|
|
|
|
p.Current = strStatus
|
|
|
|
p.Error = error
|
|
|
|
p.Status = strStatus
|
|
|
|
p.StatusText = statusText
|
|
|
|
|
|
|
|
u, ok := c.Get("sessUsr").(moduser.User)
|
|
|
|
if ok {
|
|
|
|
p.User = u
|
|
|
|
}
|
|
|
|
|
2023-05-06 21:50:35 +02:00
|
|
|
return c.Render(
|
|
|
|
status,
|
|
|
|
"errorPage.tmpl",
|
2023-08-24 18:43:24 +02:00
|
|
|
p,
|
2023-04-21 12:33:14 +02:00
|
|
|
)
|
|
|
|
}
|