From 6ad423ae5cac6f1f619d9d0d612d56fcd707aa2e Mon Sep 17 00:00:00 2001 From: Florian Hoss Date: Wed, 6 Apr 2022 13:40:33 +0200 Subject: [PATCH] handle error responses --- Lab01/app/templates/login.tmpl | 4 ++-- Lab01/app/templates/register.tmpl | 2 +- Lab01/app/webpage/webpage.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Lab01/app/templates/login.tmpl b/Lab01/app/templates/login.tmpl index 18e645c..f948ae6 100644 --- a/Lab01/app/templates/login.tmpl +++ b/Lab01/app/templates/login.tmpl @@ -27,8 +27,8 @@ setCookie("username", response.data.username, 1); redirect("/"); }) - .catch((response) => { - showErrorToast(response.message); + .catch((err) => { + showErrorToast(err.response.data.message); }); } diff --git a/Lab01/app/templates/register.tmpl b/Lab01/app/templates/register.tmpl index dbf708d..0c7ece4 100644 --- a/Lab01/app/templates/register.tmpl +++ b/Lab01/app/templates/register.tmpl @@ -26,7 +26,7 @@ redirect("/login"); }) .catch((err) => { - showErrorToast(err.message); + showErrorToast(err.response.data.message); }); } diff --git a/Lab01/app/webpage/webpage.go b/Lab01/app/webpage/webpage.go index 56e3be6..747b5ab 100644 --- a/Lab01/app/webpage/webpage.go +++ b/Lab01/app/webpage/webpage.go @@ -62,7 +62,7 @@ func (wp *Webpage) defineRoutes() { username, uExisting := c.GetPostForm("username") password, pExisting := c.GetPostForm("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 } success := wp.Database.LoginUser(username, password) @@ -76,7 +76,7 @@ func (wp *Webpage) defineRoutes() { username, uExisting := c.GetPostForm("username") password, pExisting := c.GetPostForm("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 } err := wp.Database.CreateUser(username, password)