Skip to content

Commit

Permalink
Fix CosmosDB for latest API version
Browse files Browse the repository at this point in the history
Signed-off-by: Bernd Verst <github@bernd.dev>
  • Loading branch information
berndverst committed May 3, 2024
1 parent 7d50eac commit bb1db42
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions state/azure/cosmosdb/cosmosdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ type CosmosItem struct {
const (
metadataPartitionKey = "partitionKey"
defaultTimeout = 20 * time.Second
statusNotFound = "NotFound"
)

// Policy that makes all queries cross-partition
Expand Down Expand Up @@ -228,8 +227,7 @@ func (c *StateStore) Get(ctx context.Context, req *state.GetRequest) (*state.Get
defer cancel()
readItem, err := c.client.ReadItem(readCtx, azcosmos.NewPartitionKeyString(partitionKey), req.Key, &options)
if err != nil {
var responseErr *azcore.ResponseError
if errors.As(err, &responseErr) && responseErr.ErrorCode == "NotFound" {
if isNotFoundError(err) {
return &state.GetResponse{}, nil
}
return nil, err
Expand Down Expand Up @@ -685,14 +683,16 @@ func populatePartitionMetadata(key string, requestMetadata map[string]string) st
}

func isNotFoundError(err error) bool {
fmt.Printf("Check isNotFoundError: %v\n", err)
if err == nil {
return false
}

if requestError, ok := err.(*azcore.ResponseError); ok {
if requestError.ErrorCode == statusNotFound {
if requestError.StatusCode == 404 {
return true
}
// we previously checked the error code, but unfortunately this is not stable between API versions
}

return false
Expand Down

0 comments on commit bb1db42

Please sign in to comment.