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:
parent
f1abbc5a07
commit
f52ad5f03a
@ -38,6 +38,7 @@ func register(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
authController, err := controller.MakeAuthController()
|
authController, err := controller.MakeAuthController()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -49,8 +50,9 @@ func register(c *gin.Context) {
|
|||||||
|
|
||||||
err = authController.Register(transaction.Username, transaction.Password, transaction.RepeatPassword)
|
err = authController.Register(transaction.Username, transaction.Password, transaction.RepeatPassword)
|
||||||
|
|
||||||
|
// TODO: handle server errors/register violations separetly
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"error": err.Error(),
|
"error": err.Error(),
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
@ -84,14 +86,14 @@ func login(c *gin.Context) {
|
|||||||
|
|
||||||
token, ok, err := authController.Login(transaction.Username, transaction.Password)
|
token, ok, err := authController.Login(transaction.Username, transaction.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"error": err.Error(),
|
"error": err.Error(),
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
c.JSON(http.StatusUnauthorized, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"error": "bad credentials",
|
"error": "bad credentials",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user