Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/rdkcentral/xconfadmin/common"
ccommon "github.com/rdkcentral/xconfadmin/common"
xhttp "github.com/rdkcentral/xconfadmin/http"

log "github.com/sirupsen/logrus"
)

func GetIpMacRuleConfigurationHandler(w http.ResponseWriter, r *http.Request) {
Expand All @@ -24,6 +26,7 @@ func GetIpMacRuleConfigurationHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write(b)
} else {
log.WithFields(log.Fields{"error": err}).Error("failed to marshal ip mac rule config")
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
}
Expand Down
5 changes: 5 additions & 0 deletions adminapi/queries/percentfilter_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func GetCalculatedHashAndPercentHandler(w http.ResponseWriter, r *http.Request)
}
jsonResponse, err := json.Marshal(response)
if err != nil {
log.WithFields(log.Fields{"error": err}).Error("failed to marshal JSON response")
http.Error(w, "Failed to marshal JSON response", http.StatusInternalServerError)
return
}
Expand All @@ -99,6 +100,7 @@ func UpdatePercentFilterGlobalHandler(w http.ResponseWriter, r *http.Request) {
// r.Body is already drained in the middleware
xw, ok := w.(*xwhttp.XResponseWriter)
if !ok {
log.Error("failed to cast responsewriter in UpdatePercentFilterGlobalHandler")
xhttp.AdminError(w, xwcommon.NewRemoteErrorAS(http.StatusInternalServerError, "responsewriter cast error"))
return
}
Expand Down Expand Up @@ -149,6 +151,7 @@ func GetPercentFilterGlobalHandler(w http.ResponseWriter, r *http.Request) {

globalpercent, err := GetPercentFilterGlobal(applicationType)
if err != nil {
log.WithFields(log.Fields{"error": err}).Error("failed to get global percent filter")
xhttp.WriteAdminErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("unable to get globalpercent reponse. error: %v", err))
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This handler returns an error message containing typos ("reponse"), which will be surfaced to API clients. Please correct the wording (and consider adding a space in "globalpercent" -> "global percent" for readability).

Suggested change
xhttp.WriteAdminErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("unable to get globalpercent reponse. error: %v", err))
xhttp.WriteAdminErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("unable to get global percent response. error: %v", err))

Copilot uses AI. Check for mistakes.
return
Comment on lines 152 to 156
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetPercentFilterGlobal currently always returns nil error (it logs and then returns globalPercentage, nil), so this if err != nil branch is effectively dead/unreachable. Either propagate the DB error from GetPercentFilterGlobal so callers can handle it, or remove the error return/branch to avoid misleading control flow.

Copilot uses AI. Check for mistakes.
}
Expand Down Expand Up @@ -209,6 +212,7 @@ func GetGlobalPercentFilterHandler(w http.ResponseWriter, r *http.Request) {

globalpercent, err := GetGlobalPercentFilter(applicationType)
if err != nil {
log.WithFields(log.Fields{"error": err}).Error("failed to get global percent filter")
xhttp.WriteAdminErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("unable to get globalpercent reponse. error: %v", err))
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This handler returns an error message containing typos ("reponse"), which will be surfaced to API clients. Please correct the wording (and consider adding a space in "globalpercent" -> "global percent" for readability).

Suggested change
xhttp.WriteAdminErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("unable to get globalpercent reponse. error: %v", err))
xhttp.WriteAdminErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("unable to get global percent response. error: %v", err))

Copilot uses AI. Check for mistakes.
return
Comment on lines 213 to 217
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetGlobalPercentFilter currently always returns nil error, so this if err != nil branch is effectively dead/unreachable. Either return an actual error from GetGlobalPercentFilter (e.g., when DB calls fail) or simplify the API/handler to remove the unused error path.

Copilot uses AI. Check for mistakes.
}
Expand Down Expand Up @@ -265,6 +269,7 @@ func GetCalculatedHashAndPercent(w http.ResponseWriter, r *http.Request) {
}
jsonResponse, err := json.Marshal(response)
if err != nil {
log.WithFields(log.Fields{"error": err}).Error("failed to marshal JSON response")
http.Error(w, "Failed to marshal JSON response", http.StatusInternalServerError)
return
}
Expand Down
1 change: 1 addition & 0 deletions adminapi/xcrp/recooking_lockdown_settings_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func PostRecookingLockdownSettingsHandler(w http.ResponseWriter, r *http.Request
var lockdownSettingFromDB *common.LockdownSettings
lockdownSettingFromDB, err = lockdown.GetLockdownSettings()
if err != nil {
log.WithFields(log.Fields{"error": err}).Error("failed to get lockdown settings")
http.Error(w, err.Error(), http.StatusInternalServerError)
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This handler mostly uses xhttp.WriteAdminErrorResponse / xhttp.AdminError for error responses, but this branch uses http.Error, which changes the response format for clients (plain text vs the usual admin error payload). Consider switching this to xhttp.WriteAdminErrorResponse for consistency with the rest of the handler.

Suggested change
http.Error(w, err.Error(), http.StatusInternalServerError)
xhttp.WriteAdminErrorResponse(w, http.StatusInternalServerError, err.Error())

Copilot uses AI. Check for mistakes.
return
}
Expand Down
5 changes: 5 additions & 0 deletions adminapi/xcrp/recooking_status_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ type RecookingStatus struct {
func GetRecookingStatusHandler(w http.ResponseWriter, r *http.Request) {
cc, ok := db.GetDatabaseClient().(*db.CassandraClient)
if !ok {
log.Error("internal server error: Database client is not Cassandra client")
http.Error(w, "Database client is not Cassandra client", http.StatusInternalServerError)
return
}

status, updatedTime, err := cc.CheckFinalRecookingStatus(DEFAULT_XCRP_SERVICE_NAME)
if err != nil {
log.WithFields(log.Fields{"error": err}).Error("failed to check recooking status")
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
Expand Down Expand Up @@ -60,17 +62,20 @@ func GetRecookingStatusHandler(w http.ResponseWriter, r *http.Request) {
func GetRecookingStatusDetailsHandler(w http.ResponseWriter, r *http.Request) {
cc, ok := db.GetDatabaseClient().(*db.CassandraClient)
if !ok {
log.Error("Database client is not Cassandra client")
http.Error(w, "Database client is not Cassandra client", http.StatusInternalServerError)
return
}
statuses, err := cc.GetRecookingStatusDetails()
if err != nil {
log.WithFields(log.Fields{"error": err}).Error("failed to get recooking status details")
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

response, err := json.Marshal(statuses)
if err != nil {
log.WithFields(log.Fields{"error": err}).Error("failed to marshal recooking status details")
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
Expand Down
Loading