fix: improve error messages

This commit is contained in:
Gucheng Wang 2022-03-07 15:15:59 +08:00
parent 8a9cc2eb8f
commit 3602d9b9a7
4 changed files with 9 additions and 9 deletions

View File

@ -16,6 +16,7 @@ package controllers
import (
"encoding/json"
"fmt"
"github.com/astaxie/beego/utils/pagination"
"github.com/casdoor/casdoor/object"
@ -85,7 +86,7 @@ func (c *ApiController) GetUserApplication() {
id := c.Input().Get("id")
user := object.GetUser(id)
if user == nil {
c.ResponseError("No such user.")
c.ResponseError(fmt.Sprintf("The user: %s doesn't exist", id))
return
}

View File

@ -192,7 +192,7 @@ func (c *ApiController) Login() {
user = object.GetUserByFields(form.Organization, form.Username)
if user == nil {
c.ResponseError("No such user.")
c.ResponseError(fmt.Sprintf("The user: %s/%s doesn't exist", form.Organization, form.Username))
return
}
} else {

View File

@ -190,7 +190,7 @@ func (c *ApiController) GetEmailAndPhone() {
user := object.GetUserByFields(form.Organization, form.Username)
if user == nil {
c.ResponseError("No such user.")
c.ResponseError(fmt.Sprintf("The user: %s/%s doesn't exist", form.Organization, form.Username))
return
}
@ -226,7 +226,7 @@ func (c *ApiController) SetPassword() {
requestUserId := c.GetSessionUsername()
if requestUserId == "" {
c.ResponseError("Please login first.")
c.ResponseError("Please login first")
return
}

View File

@ -68,13 +68,12 @@ func (c *ApiController) SendVerificationCode() {
organization := object.GetOrganization(orgId)
application := object.GetApplicationByOrganizationName(organization.Name)
if checkUser == "true" && user == nil &&
object.GetUserByFields(organization.Name, dest) == nil {
c.ResponseError("No such user.")
if checkUser == "true" && user == nil && object.GetUserByFields(organization.Name, dest) == nil {
c.ResponseError("Please login first")
return
}
sendResp := errors.New("Invalid dest type.")
sendResp := errors.New("Invalid dest type")
switch destType {
case "email":
if !util.IsEmailValid(dest) {
@ -121,7 +120,7 @@ func (c *ApiController) ResetEmailOrPhone() {
user := object.GetUser(userId)
if user == nil {
c.ResponseError("No such user.")
c.ResponseError(fmt.Sprintf("The user: %s doesn't exist", userId))
return
}