Added Status codes

This commit is contained in:
Phil 2021-12-08 16:50:22 +01:00
parent b07f3868ef
commit c5c268d779
No known key found for this signature in database
GPG key ID: 91884FA482AA7CB3

View file

@ -17,7 +17,7 @@ type eurl struct {
func Posthome(c *fiber.Ctx) error { func Posthome(c *fiber.Ctx) error {
u := new(eurl) u := new(eurl)
if err := c.BodyParser(u); err != nil { if err := c.BodyParser(u); err != nil {
return c.Render("views/home", fiber.Map{ return c.Status(500).Render("views/home", fiber.Map{
"ERR": "Parsing Error", "ERR": "Parsing Error",
"GitCommitShort": utils.GitCommitShort, "GitCommitShort": utils.GitCommitShort,
"GitBranch": utils.GitBranch, "GitBranch": utils.GitBranch,
@ -26,7 +26,7 @@ func Posthome(c *fiber.Ctx) error {
} }
if !regexp.MustCompile(`^(http|https|mailto|ts3server)://`).MatchString(u.URL) { if !regexp.MustCompile(`^(http|https|mailto|ts3server)://`).MatchString(u.URL) {
return c.Render("views/home", fiber.Map{ return c.Status(424).Render("views/home", fiber.Map{
"ERR": "Invalid URL, please check and try again.", "ERR": "Invalid URL, please check and try again.",
"GitCommitShort": utils.GitCommitShort, "GitCommitShort": utils.GitCommitShort,
"GitBranch": utils.GitBranch, "GitBranch": utils.GitBranch,
@ -37,7 +37,7 @@ func Posthome(c *fiber.Ctx) error {
id, err := gonanoid.New(8) id, err := gonanoid.New(8)
if err != nil { if err != nil {
return c.Render("views/home", fiber.Map{ return c.Status(500).Render("views/home", fiber.Map{
"ERR": err.Error(), "ERR": err.Error(),
"GitCommitShort": utils.GitCommitShort, "GitCommitShort": utils.GitCommitShort,
"GitBranch": utils.GitBranch, "GitBranch": utils.GitBranch,
@ -48,7 +48,7 @@ func Posthome(c *fiber.Ctx) error {
err = db.Client.Set(id, u.URL, 1296000*time.Second).Err() err = db.Client.Set(id, u.URL, 1296000*time.Second).Err()
if err != nil { if err != nil {
return c.Render("views/home", fiber.Map{ return c.Status(500).Render("views/home", fiber.Map{
"ERR": err.Error(), "ERR": err.Error(),
"GitCommitShort": utils.GitCommitShort, "GitCommitShort": utils.GitCommitShort,
"GitBranch": utils.GitBranch, "GitBranch": utils.GitBranch,
@ -58,7 +58,7 @@ func Posthome(c *fiber.Ctx) error {
fURL := utils.URL + id fURL := utils.URL + id
return c.Render("views/home", fiber.Map{ return c.Status(201).Render("views/home", fiber.Map{
"URL": fURL, "URL": fURL,
"GitCommitShort": utils.GitCommitShort, "GitCommitShort": utils.GitCommitShort,
"GitBranch": utils.GitBranch, "GitBranch": utils.GitBranch,