Skip to content

Commit a8fd206

Browse files
committed
fix: enhanced api response
1 parent 62ade03 commit a8fd206

File tree

4 files changed

+44
-14
lines changed

4 files changed

+44
-14
lines changed

api/cluster/EnvironmentRestHandler.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,11 +447,15 @@ func (impl EnvironmentRestHandlerImpl) GetCombinedEnvironmentListForDropDownByCl
447447
id, err := strconv.Atoi(clusterId)
448448
if err != nil {
449449
impl.logger.Errorw("request err, GetCombinedEnvironmentListForDropDownByClusterIds", "err", err, "clusterIdString", clusterIdString)
450-
common.WriteJsonResp(w, err, "please send valid cluster Ids", http.StatusBadRequest)
450+
common.HandleParameterError(w, r, "ids", clusterIdString)
451451
return
452452
}
453453
clusterIds = append(clusterIds, id)
454454
}
455+
} else {
456+
impl.logger.Errorw("request err empty query param, GetCombinedEnvironmentListForDropDownByClusterIds", "err", err, "clusterIdString", clusterIdString)
457+
common.HandleParameterError(w, r, "ids", clusterIdString)
458+
return
455459
}
456460
token := r.Header.Get("token")
457461
clusters, err := impl.environmentClusterMappingsService.GetCombinedEnvironmentListForDropDownByClusterIds(token, clusterIds, impl.rbacEnforcementUtil.CheckAuthorizationForGlobalEnvironment)

api/devtronResource/DevtronResourceHistoryRestHandler.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,16 @@ func (handler *HistoryRestHandlerImpl) GetDeploymentHistory(w http.ResponseWrite
5454
queryParams := apiBean.GetHistoryQueryParams{}
5555
err := decoder.Decode(&queryParams, v)
5656
if err != nil {
57+
handler.logger.Errorw("error in decoding query parameters", "queryParams", v, "err", err)
5758
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
5859
return
5960
}
61+
// Validating that filterCriteria is provided
62+
if len(queryParams.FilterCriteria) == 0 {
63+
handler.logger.Errorw("missing required filterCriteria parameter")
64+
common.HandleParameterError(w, r, "filterCriteria", "")
65+
return
66+
}
6067
decodedReqBean, err := handler.apiReqDecoderService.GetFilterCriteriaParamsForDeploymentHistory(queryParams.FilterCriteria)
6168
if err != nil {
6269
handler.logger.Errorw("error in getting filter criteria params", "err", err, "filterCriteria", queryParams.FilterCriteria)

api/restHandler/app/pipeline/AutoCompleteRestHandler.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,11 @@ func (handler DevtronAppAutoCompleteRestHandlerImpl) GetAppListForAutocomplete(w
136136
return
137137
}
138138
} else {
139-
teamIdInt, err = strconv.Atoi(teamId)
139+
teamIdInt, err = common.ExtractIntPathParamWithContext(w, r, "teamId", teamId+" team")
140+
if err != nil {
141+
// Error already written by ExtractIntPathParamWithContext
142+
return
143+
}
140144
if err != nil {
141145
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
142146
return

api/restHandler/app/pipeline/configure/BuildPipelineRestHandler.go

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,15 +1209,21 @@ func (handler *PipelineConfigRestHandlerImpl) FetchMaterialInfo(w http.ResponseW
12091209

12101210
func (handler *PipelineConfigRestHandlerImpl) GetCIPipelineById(w http.ResponseWriter, r *http.Request) {
12111211
token := r.Header.Get("token")
1212-
vars := mux.Vars(r)
1213-
appId, err := strconv.Atoi(vars["appId"])
1212+
// vars := mux.Vars(r)
1213+
//appId, err := strconv.Atoi(vars["appId"])
1214+
appId, err := common.ExtractIntPathParamWithContext(w, r, "appId", "app")
12141215
if err != nil {
1215-
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
1216+
// response already written by ExtractIntPathParamWithContext
1217+
//common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
1218+
handler.Logger.Error("request err getting , GetCIPipelineById", "appId", appId, "err", err)
12161219
return
12171220
}
1218-
pipelineId, err := strconv.Atoi(vars["pipelineId"])
1221+
//pipelineId, err := strconv.Atoi(vars["pipelineId"])
1222+
pipelineId, err := common.ExtractIntPathParamWithContext(w, r, "pipelineId", "pipeline")
12191223
if err != nil {
1220-
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
1224+
// response already written by ExtractIntPathParamWithContext
1225+
// common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
1226+
handler.Logger.Error("request err getting , GetCIPipelineById", "pipelineId", pipelineId, "err", err)
12211227
return
12221228
}
12231229

@@ -1711,20 +1717,29 @@ func (handler *PipelineConfigRestHandlerImpl) FetchWorkflowDetails(w http.Respon
17111717
common.HandleUnauthorized(w, r)
17121718
return
17131719
}
1714-
vars := mux.Vars(r)
1715-
appId, err := strconv.Atoi(vars["appId"])
1720+
// vars := mux.Vars(r)
1721+
// appId, err = strconv.Atoi(vars["appId"])
1722+
appId, err := common.ExtractIntPathParamWithContext(w, r, "appId", "app")
17161723
if err != nil {
1717-
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
1724+
// response already written by ExtractIntPathParamWithContext
1725+
// common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
1726+
handler.Logger.Error("request err getting , FetchWorkflowDetails", "appId", appId, "err", err)
17181727
return
17191728
}
1720-
pipelineId, err := strconv.Atoi(vars["pipelineId"])
1729+
// pipelineId, err := strconv.Atoi(vars["pipelineId"])
1730+
pipelineId, err := common.ExtractIntPathParamWithContext(w, r, "pipelineId", "pipeline")
17211731
if err != nil {
1722-
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
1732+
// response already written by ExtractIntPathParamWithContext
1733+
// common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
1734+
handler.Logger.Error("request err getting , FetchWorkflowDetails", "pipelineId", pipelineId, "err", err)
17231735
return
17241736
}
1725-
buildId, err := strconv.Atoi(vars["workflowId"])
1737+
// buildId, err := strconv.Atoi(vars["workflowId"])
1738+
buildId, err := common.ExtractIntPathParamWithContext(w, r, "workflowId", "workflow")
17261739
if err != nil || buildId == 0 {
1727-
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
1740+
// response already written by ExtractIntPathParamWithContext
1741+
// common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
1742+
handler.Logger.Error("request err getting , FetchWorkflowDetails", "buildId", buildId, "err", err)
17281743
return
17291744
}
17301745
handler.Logger.Infow("request payload, FetchWorkflowDetails", "appId", appId, "pipelineId", pipelineId, "buildId", buildId, "buildId", buildId)

0 commit comments

Comments
 (0)