mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
apigateway: reword error messages
This commit is contained in:
@@ -996,7 +996,7 @@ func (h *AuthHandlers) getPermissionDetails(ctx context.Context, w http.Response
|
||||
|
||||
_, query, body := appsrv.FetchEnv(ctx, w, req)
|
||||
if body == nil {
|
||||
httperrors.InvalidInputError(ctx, w, "body is empty")
|
||||
httperrors.InvalidInputError(ctx, w, "request body is empty")
|
||||
return
|
||||
}
|
||||
var name string
|
||||
@@ -1030,7 +1030,7 @@ func (h *AuthHandlers) doCreatePolicies(ctx context.Context, w http.ResponseWrit
|
||||
// }
|
||||
_, _, body := appsrv.FetchEnv(ctx, w, req)
|
||||
if body == nil {
|
||||
httperrors.InvalidInputError(ctx, w, "body is empty")
|
||||
httperrors.InvalidInputError(ctx, w, "request body is empty")
|
||||
return
|
||||
}
|
||||
s := auth.GetSession(ctx, t, FetchRegion(req), "")
|
||||
@@ -1114,7 +1114,7 @@ func (h *AuthHandlers) resetUserPassword(ctx context.Context, w http.ResponseWri
|
||||
|
||||
_, _, body := appsrv.FetchEnv(ctx, w, req)
|
||||
if body == nil {
|
||||
httperrors.InvalidInputError(ctx, w, "body is empty")
|
||||
httperrors.InvalidInputError(ctx, w, "request body is empty")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1150,7 +1150,7 @@ func (h *AuthHandlers) resetUserPassword(ctx context.Context, w http.ResponseWri
|
||||
return
|
||||
}
|
||||
}
|
||||
httperrors.InputParameterError(ctx, w, "密码错误")
|
||||
httperrors.InputParameterError(ctx, w, "wrong password")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -205,7 +205,7 @@ func validateTotpRecoverySecrets(s *mcclient.ClientSession, uid string, question
|
||||
func initTotpSecrets(ctx context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
t, authToken, err := fetchAuthInfo(ctx, req)
|
||||
if err != nil {
|
||||
httperrors.InvalidCredentialError(ctx, w, "fetchAuthInfo fail %s", err)
|
||||
httperrors.InvalidCredentialError(ctx, w, "fetchAuthInfo fail: %s", err)
|
||||
return
|
||||
}
|
||||
if authToken.IsTotpInitialized() {
|
||||
@@ -232,14 +232,14 @@ func initTotpSecrets(ctx context.Context, w http.ResponseWriter, req *http.Reque
|
||||
func validatePasscodeHandler(ctx context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
t, authToken, err := fetchAuthInfo(ctx, req)
|
||||
if err != nil {
|
||||
httperrors.InvalidCredentialError(ctx, w, "fetchAuthInfo fail %s", err)
|
||||
httperrors.InvalidCredentialError(ctx, w, "fetchAuthInfo fail: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
_, _, body := appsrv.FetchEnv(ctx, w, req)
|
||||
if body == nil {
|
||||
httperrors.InvalidInputError(ctx, w, "body is empty")
|
||||
httperrors.InvalidInputError(ctx, w, "request body is empty")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -271,14 +271,14 @@ func validatePasscodeHandler(ctx context.Context, w http.ResponseWriter, req *ht
|
||||
func resetTotpSecrets(ctx context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
t, _, err := fetchAuthInfo(ctx, req)
|
||||
if err != nil {
|
||||
httperrors.InvalidCredentialError(ctx, w, "fetchAuthInfo fail %s", err)
|
||||
httperrors.InvalidCredentialError(ctx, w, "fetchAuthInfo fail: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
_, _, body := appsrv.FetchEnv(ctx, w, req)
|
||||
if body == nil {
|
||||
httperrors.InvalidInputError(ctx, w, "body is empty")
|
||||
httperrors.InvalidInputError(ctx, w, "request body is empty")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -309,7 +309,7 @@ func resetTotpSecrets(ctx context.Context, w http.ResponseWriter, req *http.Requ
|
||||
func listTotpRecoveryQuestions(ctx context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
t, _, err := fetchAuthInfo(ctx, req)
|
||||
if err != nil {
|
||||
httperrors.InvalidCredentialError(ctx, w, "fetchAuthInfo fail %s", err)
|
||||
httperrors.InvalidCredentialError(ctx, w, "fetchAuthInfo fail: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -335,14 +335,14 @@ func listTotpRecoveryQuestions(ctx context.Context, w http.ResponseWriter, req *
|
||||
func resetTotpRecoveryQuestions(ctx context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
t, _, err := fetchAuthInfo(ctx, req)
|
||||
if err != nil {
|
||||
httperrors.InvalidCredentialError(ctx, w, "fetchAuthInfo fail %s", err)
|
||||
httperrors.InvalidCredentialError(ctx, w, "fetchAuthInfo fail: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
_, _, body := appsrv.FetchEnv(ctx, w, req)
|
||||
if body == nil {
|
||||
httperrors.InvalidInputError(ctx, w, "body is empty")
|
||||
httperrors.InvalidInputError(ctx, w, "request body is empty")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -170,7 +170,7 @@ func (h *AuthHandlers) handleSsoLogin(ctx context.Context, w http.ResponseWriter
|
||||
case "POST":
|
||||
formData, err := appsrv.Fetch(req)
|
||||
if err != nil {
|
||||
httperrors.InputParameterError(ctx, w, "fetch formdata error: %s", err)
|
||||
httperrors.InputParameterError(ctx, w, "fetch form data error: %s", err)
|
||||
}
|
||||
body, err = jsonutils.ParseQueryString(string(formData))
|
||||
if err != nil {
|
||||
|
||||
@@ -42,6 +42,8 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/util/httputils"
|
||||
)
|
||||
|
||||
const contentTypeSpreadsheet = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
||||
|
||||
const (
|
||||
HOST_MAC = "*MAC地址"
|
||||
HOST_NAME = "*名称"
|
||||
@@ -154,8 +156,8 @@ func (mh *MiscHandler) DoBatchHostRegister(ctx context.Context, w http.ResponseW
|
||||
|
||||
fileHeader := hostfiles[0].Header
|
||||
contentType := fileHeader.Get("Content-Type")
|
||||
if contentType != "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" {
|
||||
e := httperrors.NewInputParameterError("Wrong content type %s, required application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", contentType)
|
||||
if contentType != contentTypeSpreadsheet {
|
||||
e := httperrors.NewInputParameterError("Wrong content type %s, want %s", contentType, contentTypeSpreadsheet)
|
||||
httperrors.JsonClientError(ctx, w, e)
|
||||
return
|
||||
}
|
||||
@@ -199,7 +201,7 @@ func (mh *MiscHandler) DoBatchHostRegister(ctx context.Context, w http.ResponseW
|
||||
}
|
||||
|
||||
if !titlesOk {
|
||||
httperrors.InputParameterError(ctx, w, "template file is invalid.please check.")
|
||||
httperrors.InputParameterError(ctx, w, "template file is invalid. please check.")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -302,8 +304,8 @@ func (mh *MiscHandler) DoBatchUserRegister(ctx context.Context, w http.ResponseW
|
||||
|
||||
fileHeader := userfiles[0].Header
|
||||
contentType := fileHeader.Get("Content-Type")
|
||||
if contentType != "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" {
|
||||
e := httperrors.NewInputParameterError("Wrong content type %s, required application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", contentType)
|
||||
if contentType != contentTypeSpreadsheet {
|
||||
e := httperrors.NewInputParameterError("Wrong content type %s, want %s", contentType, contentTypeSpreadsheet)
|
||||
httperrors.JsonClientError(ctx, w, e)
|
||||
return
|
||||
}
|
||||
@@ -328,7 +330,7 @@ func (mh *MiscHandler) DoBatchUserRegister(ctx context.Context, w http.ResponseW
|
||||
// skipped header row
|
||||
rows := xlsx.GetRows("users")
|
||||
if len(rows) <= 1 {
|
||||
e := httperrors.NewInputParameterError("empty file")
|
||||
e := httperrors.NewInputParameterError("empty file content")
|
||||
httperrors.JsonClientError(ctx, w, e)
|
||||
return
|
||||
} else if len(rows) > BATCH_USER_REGISTER_QUANTITY_LIMITATION {
|
||||
@@ -431,7 +433,7 @@ func (mh *MiscHandler) getDownloadsHandler(ctx context.Context, w http.ResponseW
|
||||
params := appctx.AppContextParams(ctx)
|
||||
template, ok := params["<template_id>"]
|
||||
if !ok || len(template) == 0 {
|
||||
httperrors.InvalidInputError(ctx, w, "not found")
|
||||
httperrors.InvalidInputError(ctx, w, "template_id")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -142,11 +142,11 @@ func fetchIdList(ctx context.Context, query jsonutils.JSONObject, w http.Respons
|
||||
if e == nil && len(idlist) > 0 {
|
||||
queryDict := query.(*jsonutils.JSONDict)
|
||||
queryDict.Remove("id")
|
||||
log.Debugf("Get idlist: %s", idlist)
|
||||
log.Debugf("Get id list: %s", idlist)
|
||||
return jsonutils.JSONArray2StringArray(idlist)
|
||||
} else {
|
||||
log.Debugf("Cannot find idlist in query: %s", query)
|
||||
httperrors.InvalidInputError(ctx, w, "No idlist found")
|
||||
log.Debugf("Cannot find id list in query: %s", query)
|
||||
httperrors.InvalidInputError(ctx, w, "No id list found")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user