[Cosmos] Throws better continuation token error when it's malformed (#13163)

* Throw a better continuation token error when malformed

* format

* Check for query info, otherwise error

* format

* Format and change error check

* adds another string message includes

* Format

* throw reused error

* format
This commit is contained in:
Zachary Foster 2021-01-14 10:37:35 -05:00 коммит произвёл GitHub
Родитель ea1f4e75eb
Коммит 41067fc6ee
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 38 добавлений и 6 удалений

Просмотреть файл

@ -1,7 +1,8 @@
# Release History
## 3.9.5
## 3.9.5 (2021-01-12)
- BUGFIX: Throws correct Invalid Continuation Token error when making request with malformed token
- BUGFIX: Defaults partitionKeyValue to `'[{}]'` when missing in Read/Delete bulk operations
## 3.9.4 (2021-01-04)

Просмотреть файл

@ -243,8 +243,15 @@ export class QueryIterator<T> {
return this.queryPlanPromise;
}
private needsQueryPlan(error: any): error is ErrorResponse {
return error.code === StatusCodes.BadRequest && this.resourceType === ResourceType.item;
private needsQueryPlan(error: ErrorResponse): error is ErrorResponse {
if (
error.body?.additionalErrorInfo ||
error.message.includes("Cross partition query only supports")
) {
return error.code === StatusCodes.BadRequest && this.resourceType === ResourceType.item;
} else {
throw error;
}
}
private initPromise: Promise<void>;

Просмотреть файл

@ -39,8 +39,8 @@ function prefixKeyByType(key: v2Key): Buffer {
return Buffer.from(BytePrefix.Undefined, "hex");
case "undefined":
return Buffer.from(BytePrefix.Undefined, "hex");
default:
throw new Error(`Unexpected type: ${typeof key}`);
default:
throw new Error(`Unexpected type: ${typeof key}`);
}
}

Просмотреть файл

@ -1,7 +1,13 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import assert from "assert";
import { CosmosClient, Constants, Container, PluginConfig, CosmosClientOptions } from "../../../src";
import {
CosmosClient,
Constants,
Container,
PluginConfig,
CosmosClientOptions
} from "../../../src";
import { removeAllDatabases, getTestContainer } from "../common/TestHelpers";
import { endpoint, masterKey } from "../common/_testConfig";
import { ResourceType, HTTPMethod, StatusCodes } from "../../../src";

Просмотреть файл

@ -124,6 +124,24 @@ describe("Queries", function() {
"second batch element should be doc3"
);
});
it("fails with invalid continuation token", async function() {
let queryIterator = resources.container.items.readAll({
maxItemCount: 2
});
const firstResponse = await queryIterator.fetchNext();
assert(firstResponse.continuationToken);
queryIterator = resources.container.items.readAll({
maxItemCount: 2,
continuationToken: "junk"
});
try {
await queryIterator.fetchNext();
} catch (e) {
assert(e.message.includes("Invalid Continuation Token"));
}
});
describe("SUM query iterator", function() {
this.timeout(process.env.MOCHA_TIMEOUT || 30000);