2024-02-05 02:24:55 +00:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"codeberg.org/rimgo/rimgo/static"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func RenderError(c *fiber.Ctx, code int) error {
|
2024-02-05 21:26:54 +00:00
|
|
|
if !strings.Contains(c.Get("Accept"), "html") && c.Params("extension") != "" {
|
2024-02-05 02:24:55 +00:00
|
|
|
codeStr := "generic"
|
|
|
|
if code != 0 {
|
|
|
|
codeStr = strconv.Itoa(code)
|
|
|
|
}
|
|
|
|
img, _ := static.GetFiles().ReadFile("img/error-" + codeStr + ".png")
|
|
|
|
c.Set("Content-Type", "image/png")
|
|
|
|
return c.Status(code).Send(img)
|
|
|
|
} else {
|
|
|
|
return c.Status(code).Render("errors/" + strconv.Itoa(code), fiber.Map{
|
|
|
|
"path": c.Path(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|