handle error responses

This commit is contained in:
Florian Hoss 2022-04-06 13:40:33 +02:00
parent 5b2252d6bd
commit 6ad423ae5c
3 changed files with 5 additions and 5 deletions

View file

@ -27,8 +27,8 @@
setCookie("username", response.data.username, 1); setCookie("username", response.data.username, 1);
redirect("/"); redirect("/");
}) })
.catch((response) => { .catch((err) => {
showErrorToast(response.message); showErrorToast(err.response.data.message);
}); });
} }
</script> </script>

View file

@ -26,7 +26,7 @@
redirect("/login"); redirect("/login");
}) })
.catch((err) => { .catch((err) => {
showErrorToast(err.message); showErrorToast(err.response.data.message);
}); });
} }
</script> </script>

View file

@ -62,7 +62,7 @@ func (wp *Webpage) defineRoutes() {
username, uExisting := c.GetPostForm("username") username, uExisting := c.GetPostForm("username")
password, pExisting := c.GetPostForm("password") password, pExisting := c.GetPostForm("password")
if uExisting == false || pExisting == false || username == "" || password == "" { if uExisting == false || pExisting == false || username == "" || password == "" {
c.JSON(400, gin.H{"message": "bad post form"}) c.JSON(400, gin.H{"message": "no valid post form"})
return return
} }
success := wp.Database.LoginUser(username, password) success := wp.Database.LoginUser(username, password)
@ -76,7 +76,7 @@ func (wp *Webpage) defineRoutes() {
username, uExisting := c.GetPostForm("username") username, uExisting := c.GetPostForm("username")
password, pExisting := c.GetPostForm("password") password, pExisting := c.GetPostForm("password")
if uExisting == false || pExisting == false || username == "" || password == "" { if uExisting == false || pExisting == false || username == "" || password == "" {
c.JSON(400, gin.H{"message": "bad post form"}) c.JSON(400, gin.H{"message": "no valid post form"})
return return
} }
err := wp.Database.CreateUser(username, password) err := wp.Database.CreateUser(username, password)