From f52ad5f03a8598ab7bfbb325b3151df014cf4cda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?BENEDEK=20L=C3=A1szl=C3=B3?= Date: Mon, 2 Jun 2025 19:03:37 +0200 Subject: [PATCH] change resutrn codes angular expects 200 for all request, only return other if it is a server or db error --- api/auth.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/api/auth.go b/api/auth.go index 2e422d5..8fa3551 100644 --- a/api/auth.go +++ b/api/auth.go @@ -38,6 +38,7 @@ func register(c *gin.Context) { }) return } + authController, err := controller.MakeAuthController() if err != nil { @@ -49,8 +50,9 @@ func register(c *gin.Context) { err = authController.Register(transaction.Username, transaction.Password, transaction.RepeatPassword) + // TODO: handle server errors/register violations separetly if err != nil { - c.JSON(http.StatusBadRequest, gin.H{ + c.JSON(http.StatusOK, gin.H{ "error": err.Error(), }) return @@ -84,14 +86,14 @@ func login(c *gin.Context) { token, ok, err := authController.Login(transaction.Username, transaction.Password) if err != nil { - c.JSON(http.StatusInternalServerError, gin.H{ + c.JSON(http.StatusOK, gin.H{ "error": err.Error(), }) return } if !ok { - c.JSON(http.StatusUnauthorized, gin.H{ + c.JSON(http.StatusOK, gin.H{ "error": "bad credentials", }) return