From: subhash kumar singh Date: Mon, 29 May 2023 12:55:05 +0000 (+0000) Subject: Add error check if arg is nil X-Git-Tag: 2.1.0~1 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F38%2F11238%2F1;p=ric-plt%2Fricdms.git Add error check if arg is nil Implemented error check to avoid crash if `helmpkg` is nil. Issue-ID: RIC-955 Signed-off-by: subhash kumar singh Change-Id: I0c1686ea11dd6d715c2e1fca3b3bea82c9406935 --- diff --git a/pkg/restful/restful.go b/pkg/restful/restful.go index cde52e1..4e6f7a1 100644 --- a/pkg/restful/restful.go +++ b/pkg/restful/restful.go @@ -30,6 +30,7 @@ import ( ch "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/charts" dm "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/deploy" ph "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/health" + "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/models" po "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/onboard" "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/restapi" "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/restapi/operations" @@ -122,6 +123,12 @@ func (r *Restful) setupHandler() { api.ExperimentPostCustomOnboardHandler = experiment.PostCustomOnboardHandlerFunc(func(pcop experiment.PostCustomOnboardParams) middleware.Responder { ricdms.Logger.Debug("==> invoked custom onboarding") + if pcop.Helmpkg == nil { + errString := "formdata not provided with key helmpkg" + return experiment.NewPostCustomOnboardInternalServerError().WithPayload(&models.ErrorMessage{ + ErrorMessage: &errString, + }) + } defer pcop.Helmpkg.Close() return r.rh.Onboarder.CustomOnboard(pcop.Helmpkg) })