You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
580 B
30 lines
580 B
|
2 days ago
|
package common
|
||
|
|
|
||
|
|
import (
|
||
|
|
"log"
|
||
|
|
"fmt"
|
||
|
|
"github.com/gofiber/fiber/v2"
|
||
|
|
)
|
||
|
|
|
||
|
|
func Fail(err error, format string, v ...any) error {
|
||
|
|
err_format := fmt.Sprintf("ERROR: %v; %s", err, format)
|
||
|
|
log.Printf(err_format, v...)
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
func ApiError(c *fiber.Ctx, format string, args ...any) error {
|
||
|
|
c.Status(500)
|
||
|
|
|
||
|
|
log.Printf(format, args...)
|
||
|
|
|
||
|
|
return c.JSON(fiber.Map{
|
||
|
|
"error": fmt.Sprintf(format, args...),
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
func RenderError(c *fiber.Ctx, format string, args ...any) error {
|
||
|
|
return c.Render("error", fiber.Map{
|
||
|
|
"Error": fmt.Sprintf(format, args...),
|
||
|
|
})
|
||
|
|
}
|