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

View File

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

View File

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

View File

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