From 6e1d40d33936d2f98b1d2341254d367c5253d5f4 Mon Sep 17 00:00:00 2001 From: Nalu Tripician <27316859+NaluTripician@users.noreply.github.com> Date: Mon, 15 Jul 2024 13:40:20 -0700 Subject: [PATCH] ChangeFeed: Adds MalformedContinuationToken SubstatusCode to exception (#4583) --- .../Query/Core/ExceptionToCosmosException.cs | 5 ++++- .../CosmosItemTests.cs | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Microsoft.Azure.Cosmos/src/Query/Core/ExceptionToCosmosException.cs b/Microsoft.Azure.Cosmos/src/Query/Core/ExceptionToCosmosException.cs index 02c1882e26..5ee4eca609 100644 --- a/Microsoft.Azure.Cosmos/src/Query/Core/ExceptionToCosmosException.cs +++ b/Microsoft.Azure.Cosmos/src/Query/Core/ExceptionToCosmosException.cs @@ -157,7 +157,10 @@ internal override CosmosException Visit( { return CosmosExceptionFactory.CreateBadRequestException( message: malformedChangeFeedContinuationTokenException.Message, - headers: new Headers(), + headers: new Headers() + { + SubStatusCode = Documents.SubStatusCodes.MalformedContinuationToken + }, stackTrace: malformedChangeFeedContinuationTokenException.StackTrace, innerException: malformedChangeFeedContinuationTokenException, trace: trace); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs index 0ad71e7085..25b46d670f 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs @@ -3319,6 +3319,23 @@ await CosmosItemTests.GivenItemAsyncWhenMissingMemberHandlingIsErrorThenExpectsC id: itemIdThatWillNotExist, partitionKey: new Cosmos.PartitionKey(partitionKeyValue), cancellationToken: cancellationToken)); + } + + [TestMethod] + public async Task MalformedChangeFeedContinuationTokenSubStatusCodeTest() + { + FeedIterator badIterator = this.Container.GetChangeFeedStreamIterator( + ChangeFeedStartFrom.ContinuationToken("AMalformedContinuationToken"), + ChangeFeedMode.Incremental, + new ChangeFeedRequestOptions() + { + PageSizeHint = 100 + }); + + ResponseMessage response = await badIterator.ReadNextAsync(); + + Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode); + Assert.AreEqual(SubStatusCodes.MalformedContinuationToken, response.Headers.SubStatusCode); } private static async Task GivenItemStreamAsyncWhenMissingMemberHandlingIsErrorThenExpectsCosmosExceptionTestAsync(