@@ -9,13 +9,16 @@ namespace Microsoft.Azure.Cosmos.ReadFeed
99 using System . Threading ;
1010 using System . Threading . Tasks ;
1111 using Microsoft . Azure . Cosmos . CosmosElements ;
12- using Microsoft . Azure . Cosmos . Diagnostics ;
12+ using Microsoft . Azure . Cosmos . Json ;
1313 using Microsoft . Azure . Cosmos . Pagination ;
1414 using Microsoft . Azure . Cosmos . Query . Core ;
15+ using Microsoft . Azure . Cosmos . Query . Core . Exceptions ;
1516 using Microsoft . Azure . Cosmos . Query . Core . Monads ;
1617 using Microsoft . Azure . Cosmos . ReadFeed . Pagination ;
18+ using Microsoft . Azure . Cosmos . Resource . CosmosExceptions ;
1719 using Microsoft . Azure . Cosmos . Routing ;
1820 using Microsoft . Azure . Cosmos . Tracing ;
21+ using Microsoft . Azure . Documents ;
1922
2023 /// <summary>
2124 /// Cosmos feed stream iterator. This is used to get the query responses with a Stream content
@@ -113,7 +116,25 @@ public ReadFeedIteratorCore(
113116 else
114117 {
115118 CosmosString tokenAsString = ( CosmosString ) token ;
116- state = ReadFeedState . Continuation ( CosmosElement . Parse ( tokenAsString . Value ) ) ;
119+ try
120+ {
121+ state = ReadFeedState . Continuation ( CosmosElement . Parse ( tokenAsString . Value ) ) ;
122+ }
123+ catch ( Exception exception ) when ( exception . InnerException is JsonParseException )
124+ {
125+ MalformedContinuationTokenException malformedContinuationTokenException = new MalformedContinuationTokenException ( exception . Message ) ;
126+ throw CosmosExceptionFactory . CreateBadRequestException (
127+ message : $ "Malformed Continuation Token: { tokenAsString } .",
128+ headers : CosmosQueryResponseMessageHeaders . ConvertToQueryHeaders (
129+ new Headers ( ) ,
130+ default ,
131+ default ,
132+ ( int ) SubStatusCodes . MalformedContinuationToken ,
133+ default ) ,
134+ stackTrace : exception . StackTrace ,
135+ innerException : malformedContinuationTokenException ,
136+ trace : null ) ;
137+ }
117138 }
118139
119140 FeedRangeState < ReadFeedState > feedRangeState = new FeedRangeState < ReadFeedState > ( feedRange , state ) ;
0 commit comments