Error handling in get all policy instance api
Error handling in get all policy instance api
Signed-off-by: naman.gupta <naman.gupta@samsung.com>
Change-Id: I773abbb07d2c2b719acec81be17580171d1833c1
diff --git a/a1-go/pkg/restful/restful.go b/a1-go/pkg/restful/restful.go
index 28efaaa..b7e2094 100644
--- a/a1-go/pkg/restful/restful.go
+++ b/a1-go/pkg/restful/restful.go
@@ -97,7 +97,16 @@
api.A1MediatorA1ControllerGetAllInstancesForTypeHandler = a1_mediator.A1ControllerGetAllInstancesForTypeHandlerFunc(func(params a1_mediator.A1ControllerGetAllInstancesForTypeParams) middleware.Responder {
a1.Logger.Debug("handler for get all policy instance")
- return a1_mediator.NewA1ControllerGetPolicyInstanceOK().WithPayload(r.rh.GetAllPolicyInstance(models.PolicyTypeID(params.PolicyTypeID)))
+ if resp, err := r.rh.GetAllPolicyInstance(models.PolicyTypeID(params.PolicyTypeID)); err == nil {
+ if resp != nil {
+ return a1_mediator.NewA1ControllerGetAllInstancesForTypeOK().WithPayload(resp)
+ }
+ }
+ if r.rh.IsPolicyInstanceNotFound(err) {
+ return a1_mediator.NewA1ControllerGetPolicyInstanceNotFound()
+ }
+ return a1_mediator.NewA1ControllerGetAllInstancesForTypeServiceUnavailable()
+
})
return api