Update validation and error message per comments

This commit is contained in:
wang yan 2019-01-17 15:33:05 +08:00
parent 4cde11892a
commit 903e15235e
2 changed files with 6 additions and 10 deletions

View File

@ -53,11 +53,7 @@ type RobotReq struct {
// Valid put request validation // Valid put request validation
func (rq *RobotReq) Valid(v *validation.Validation) { func (rq *RobotReq) Valid(v *validation.Validation) {
switch rq.Disabled { // ToDo: add validation for access info.
case true, false:
default:
v.SetError("disabled", "must be in [true, false]")
}
} }
// RobotRep ... // RobotRep ...

View File

@ -45,13 +45,13 @@ func (r *RobotAPI) Prepare() {
pid, err := r.GetInt64FromPath(":pid") pid, err := r.GetInt64FromPath(":pid")
if err != nil || pid <= 0 { if err != nil || pid <= 0 {
text := "invalid project ID: " var errMsg string
if err != nil { if err != nil {
text += err.Error() errMsg = "failed to get project ID " + err.Error()
} else { } else {
text += fmt.Sprintf("%d", pid) errMsg = "invalid project ID: " + fmt.Sprintf("%d", pid)
} }
r.HandleBadRequest(text) r.HandleBadRequest(errMsg)
return return
} }
project, err := r.ProjectMgr.Get(pid) project, err := r.ProjectMgr.Get(pid)
@ -137,7 +137,7 @@ func (r *RobotAPI) List() {
count, err := dao.CountRobot(&query) count, err := dao.CountRobot(&query)
if err != nil { if err != nil {
r.HandleInternalServerError(fmt.Sprintf("failed to count robots %v", err)) r.HandleInternalServerError(fmt.Sprintf("failed to list robots on project: %d, %v", r.project.ProjectID, err))
return return
} }
query.Page, query.Size = r.GetPaginationParams() query.Page, query.Size = r.GetPaginationParams()