@@ -22,6 +22,7 @@ import (
2222 "context"
2323 "crypto/tls"
2424 "encoding/json"
25+ "errors"
2526 "fmt"
2627 "log/slog"
2728 "net/http"
@@ -657,21 +658,28 @@ func (c *Client) handleAPIDeployedEvent(event map[string]interface{}) {
657658 slog .String ("correlation_id" , deployedEvent .CorrelationID ))
658659 }
659660 } else if result .IsUpdate {
660- // No policies but this is an update, so remove any existing policies
661+ // API was updated and no longer has policies, remove the existing policy configuration
661662 policyID := result .StoredConfig .ID + "-policies"
662- if _ , err := c .policyManager .GetPolicy (policyID ); err == nil {
663- if err := c .policyManager .RemovePolicy (policyID ); err != nil {
664- c .logger .Error ("Failed to remove policy from policy engine" ,
665- slog .Any ("error" , err ),
663+ if err := c .policyManager .RemovePolicy (policyID ); err != nil {
664+ // Only treat "not found" as non-error (API may never have had policies)
665+ // Other errors (storage failures, snapshot update failures) should be logged as errors
666+ if errors .Is (err , storage .ErrPolicyNotFound ) {
667+ c .logger .Debug ("No policy configuration to remove" ,
666668 slog .String ("api_id" , apiID ),
667669 slog .String ("policy_id" , policyID ),
668670 slog .String ("correlation_id" , deployedEvent .CorrelationID ))
669671 } else {
670- c .logger .Info ("Successfully removed policy from policy engine" ,
672+ c .logger .Error ("Failed to remove policy configuration" ,
673+ slog .Any ("error" , err ),
671674 slog .String ("api_id" , apiID ),
672675 slog .String ("policy_id" , policyID ),
673676 slog .String ("correlation_id" , deployedEvent .CorrelationID ))
674677 }
678+ } else {
679+ c .logger .Info ("Derived policy configuration removed" ,
680+ slog .String ("api_id" , apiID ),
681+ slog .String ("policy_id" , policyID ),
682+ slog .String ("correlation_id" , deployedEvent .CorrelationID ))
675683 }
676684 }
677685 } else if c .policyManager == nil {
0 commit comments