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 d142aba
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 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 @@ -690,9 +688,10 @@ func isNotFoundError(err error) bool {
}

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 d142aba

Please sign in to comment.