@@ -26,7 +26,6 @@ import (
2626	"github.com/devtron-labs/devtron/pkg/appStore/chartGroup" 
2727	"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin" 
2828	"github.com/devtron-labs/devtron/pkg/auth/user" 
29- 	"github.com/gorilla/mux" 
3029	"go.uber.org/zap" 
3130	"gopkg.in/go-playground/validator.v9" 
3231)
@@ -67,7 +66,7 @@ type ChartGroupRestHandler interface {
6766func  (impl  * ChartGroupRestHandlerImpl ) CreateChartGroup (w  http.ResponseWriter , r  * http.Request ) {
6867	userId , err  :=  impl .userAuthService .GetLoggedInUser (r )
6968	if  userId  ==  0  ||  err  !=  nil  {
70- 		common .WriteJsonResp (w , err ,  "Unauthorized User" ,  http . StatusUnauthorized )
69+ 		common .HandleUnauthorized (w , r )
7170		return 
7271	}
7372	decoder  :=  json .NewDecoder (r .Body )
@@ -112,7 +111,7 @@ func (impl *ChartGroupRestHandlerImpl) CreateChartGroup(w http.ResponseWriter, r
112111func  (impl  * ChartGroupRestHandlerImpl ) UpdateChartGroup (w  http.ResponseWriter , r  * http.Request ) {
113112	userId , err  :=  impl .userAuthService .GetLoggedInUser (r )
114113	if  userId  ==  0  ||  err  !=  nil  {
115- 		common .WriteJsonResp (w , err ,  "Unauthorized User" ,  http . StatusUnauthorized )
114+ 		common .HandleUnauthorized (w , r )
116115		return 
117116	}
118117	decoder  :=  json .NewDecoder (r .Body )
@@ -153,7 +152,7 @@ func (impl *ChartGroupRestHandlerImpl) UpdateChartGroup(w http.ResponseWriter, r
153152func  (impl  * ChartGroupRestHandlerImpl ) SaveChartGroupEntries (w  http.ResponseWriter , r  * http.Request ) {
154153	userId , err  :=  impl .userAuthService .GetLoggedInUser (r )
155154	if  userId  ==  0  ||  err  !=  nil  {
156- 		common .WriteJsonResp (w , err ,  "Unauthorized User" ,  http . StatusUnauthorized )
155+ 		common .HandleUnauthorized (w , r )
157156		return 
158157	}
159158	decoder  :=  json .NewDecoder (r .Body )
@@ -187,14 +186,14 @@ func (impl *ChartGroupRestHandlerImpl) SaveChartGroupEntries(w http.ResponseWrit
187186func  (impl  * ChartGroupRestHandlerImpl ) GetChartGroupWithChartMetaData (w  http.ResponseWriter , r  * http.Request ) {
188187	userId , err  :=  impl .userAuthService .GetLoggedInUser (r )
189188	if  userId  ==  0  ||  err  !=  nil  {
190- 		common .WriteJsonResp (w , err ,  "Unauthorized User" ,  http . StatusUnauthorized )
189+ 		common .HandleUnauthorized (w , r )
191190		return 
192191	}
193- 	vars  :=  mux .Vars (r )
194- 	chartGroupId , err  :=  strconv .Atoi (vars ["chartGroupId" ])
192+ 
193+ 	// Use enhanced parameter parsing with context 
194+ 	chartGroupId , err  :=  common .ExtractIntPathParamWithContext (w , r , "chartGroupId" , "chart group" )
195195	if  err  !=  nil  {
196- 		impl .Logger .Errorw ("request err, GetChartGroupWithChartMetaData" , "err" , err , "chartGroupId" , chartGroupId )
197- 		common .WriteJsonResp (w , err , nil , http .StatusBadRequest )
196+ 		// Error already written by ExtractIntPathParamWithContext 
198197		return 
199198	}
200199
@@ -219,14 +218,14 @@ func (impl *ChartGroupRestHandlerImpl) GetChartGroupWithChartMetaData(w http.Res
219218func  (impl  * ChartGroupRestHandlerImpl ) GetChartGroupInstallationDetail (w  http.ResponseWriter , r  * http.Request ) {
220219	userId , err  :=  impl .userAuthService .GetLoggedInUser (r )
221220	if  userId  ==  0  ||  err  !=  nil  {
222- 		common .WriteJsonResp (w , err ,  "Unauthorized User" ,  http . StatusUnauthorized )
221+ 		common .HandleUnauthorized (w , r )
223222		return 
224223	}
225- 	vars  :=  mux .Vars (r )
226- 	chartGroupId , err  :=  strconv .Atoi (vars ["chartGroupId" ])
224+ 
225+ 	// Use enhanced parameter parsing with context 
226+ 	chartGroupId , err  :=  common .ExtractIntPathParamWithContext (w , r , "chartGroupId" , "chart group" )
227227	if  err  !=  nil  {
228- 		impl .Logger .Errorw ("request err, GetChartGroupInstallationDetail" , "err" , err , "chartGroupId" , chartGroupId )
229- 		common .WriteJsonResp (w , err , nil , http .StatusBadRequest )
228+ 		// Error already written by ExtractIntPathParamWithContext 
230229		return 
231230	}
232231
@@ -251,7 +250,7 @@ func (impl *ChartGroupRestHandlerImpl) GetChartGroupInstallationDetail(w http.Re
251250func  (impl  * ChartGroupRestHandlerImpl ) GetChartGroupList (w  http.ResponseWriter , r  * http.Request ) {
252251	userId , err  :=  impl .userAuthService .GetLoggedInUser (r )
253252	if  userId  ==  0  ||  err  !=  nil  {
254- 		common .WriteJsonResp (w , err ,  "Unauthorized User" ,  http . StatusUnauthorized )
253+ 		common .HandleUnauthorized (w , r )
255254		return 
256255	}
257256
@@ -286,7 +285,7 @@ func (impl *ChartGroupRestHandlerImpl) GetChartGroupList(w http.ResponseWriter,
286285func  (impl  * ChartGroupRestHandlerImpl ) GetChartGroupListMin (w  http.ResponseWriter , r  * http.Request ) {
287286	userId , err  :=  impl .userAuthService .GetLoggedInUser (r )
288287	if  userId  ==  0  ||  err  !=  nil  {
289- 		common .WriteJsonResp (w , err ,  "Unauthorized User" ,  http . StatusUnauthorized )
288+ 		common .HandleUnauthorized (w , r )
290289		return 
291290	}
292291
@@ -321,7 +320,7 @@ func (impl *ChartGroupRestHandlerImpl) GetChartGroupListMin(w http.ResponseWrite
321320func  (impl  * ChartGroupRestHandlerImpl ) DeleteChartGroup (w  http.ResponseWriter , r  * http.Request ) {
322321	userId , err  :=  impl .userAuthService .GetLoggedInUser (r )
323322	if  userId  ==  0  ||  err  !=  nil  {
324- 		common .WriteJsonResp (w , err ,  "Unauthorized User" ,  http . StatusUnauthorized )
323+ 		common .HandleUnauthorized (w , r )
325324		return 
326325	}
327326	decoder  :=  json .NewDecoder (r .Body )
0 commit comments