mirror of
https://codeberg.org/video-prize-ranch/rimgo.git
synced 2025-12-13 19:55:21 +00:00
Errors in image format (closes #165)
This commit is contained in:
25
utils/error.go
Normal file
25
utils/error.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"codeberg.org/rimgo/rimgo/static"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func RenderError(c *fiber.Ctx, code int) error {
|
||||
if !strings.Contains(c.Get("Accept"), "html") {
|
||||
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(),
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user