optimize code of judge wether success or failed return content
This commit is contained in:
parent
ba5e5b3d1c
commit
e1886bc347
|
|
@ -159,7 +159,20 @@ func ComponentAttributeQueryHandler(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
payload := genQueryRespPayload(queryResults, tokenSlice)
|
payload := genQueryRespPayload(queryResults, tokenSlice)
|
||||||
renderRespSuccess(c, constants.RespCodeSuccess, "process completed", payload)
|
if hasAnyError(queryResults) {
|
||||||
|
renderRespFailure(c, constants.RespCodeFailed, "query completed with partial failures", payload)
|
||||||
|
} else {
|
||||||
|
renderRespSuccess(c, constants.RespCodeSuccess, "query completed successfully", payload)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func hasAnyError(results map[string]queryResult) bool {
|
||||||
|
for _, res := range results {
|
||||||
|
if res.err != nil && res.err.Code() != constants.RespCodeSuccess {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func fillRemainingErrors(results map[string]queryResult, tokens []string, err *errcode.AppError) {
|
func fillRemainingErrors(results map[string]queryResult, tokens []string, err *errcode.AppError) {
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,11 @@ func ComponentAttributeUpdateHandler(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
payload := genUpdateRespPayload(updateResults, request.AttributeConfigs)
|
payload := genUpdateRespPayload(updateResults, request.AttributeConfigs)
|
||||||
renderRespSuccess(c, constants.RespCodeSuccess, "process completed", payload)
|
if len(updateResults) > 0 {
|
||||||
|
renderRespFailure(c, constants.RespCodeFailed, "process completed with partial failures", payload)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
renderRespSuccess(c, constants.RespCodeSuccess, "process completed successfully", payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
type attributeModifyConfig struct {
|
type attributeModifyConfig struct {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue