change resutrn codes

angular expects 200 for all request, only return other if it is a server or db error
This commit is contained in:
BENEDEK László 2025-06-02 19:03:37 +02:00
parent f1abbc5a07
commit f52ad5f03a

View File

@ -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