From 329a6a8132bb84cadeecb8937e6fb4a32eff7616 Mon Sep 17 00:00:00 2001 From: Yang Luo Date: Mon, 25 Sep 2023 22:11:08 +0800 Subject: [PATCH] Fix get-pricing and get-plan API null error handling --- controllers/plan.go | 14 ++++---------- controllers/pricing.go | 6 +----- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/controllers/plan.go b/controllers/plan.go index 449534bd..d7c35140 100644 --- a/controllers/plan.go +++ b/controllers/plan.go @@ -16,7 +16,6 @@ package controllers import ( "encoding/json" - "fmt" "github.com/beego/beego/utils/pagination" "github.com/casdoor/casdoor/object" @@ -83,11 +82,8 @@ func (c *ApiController) GetPlan() { c.ResponseError(err.Error()) return } - if plan == nil { - c.ResponseError(fmt.Sprintf(c.T("plan:The plan: %s does not exist"), id)) - return - } - if includeOption { + + if plan != nil && includeOption { options, err := object.GetPermissionsByRole(plan.Role) if err != nil { c.ResponseError(err.Error()) @@ -97,11 +93,9 @@ func (c *ApiController) GetPlan() { for _, option := range options { plan.Options = append(plan.Options, option.DisplayName) } - - c.ResponseOk(plan) - } else { - c.ResponseOk(plan) } + + c.ResponseOk(plan) } // UpdatePlan diff --git a/controllers/pricing.go b/controllers/pricing.go index a1b379a7..e683e19a 100644 --- a/controllers/pricing.go +++ b/controllers/pricing.go @@ -16,7 +16,6 @@ package controllers import ( "encoding/json" - "fmt" "github.com/beego/beego/utils/pagination" "github.com/casdoor/casdoor/object" @@ -81,10 +80,7 @@ func (c *ApiController) GetPricing() { c.ResponseError(err.Error()) return } - if pricing == nil { - c.ResponseError(fmt.Sprintf(c.T("pricing:The pricing: %s does not exist"), id)) - return - } + c.ResponseOk(pricing) }