{"record":{"id":"e6ab72226584a9e2","repo":"DefinitelyTyped/DefinitelyTyped","slug":"the-query-wasn-t-accepted-by-the-server-try-again","errorCode":null,"errorMessage":"The query wasn't accepted by the server. Try again/use continuation token between API and script.","messagePattern":"The query wasn't accepted by the server\\. Try again/use continuation token between API and script\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"types/documentdb-server/documentdb-server-tests.ts","lineNumber":299,"sourceCode":"function simple(prefix: string) {\n    var collection: ICollection = getContext().getCollection();\n\n    // Query documents and take 1st item.\n    var isAccepted: boolean = collection.queryDocuments(\n        collection.getSelfLink(),\n        \"SELECT * FROM root r\",\n        function(err: IFeedCallbackError, feed: any[], options: IFeedCallbackOptions) {\n            if (err) throw err;\n\n            // Check the feed and if it's empty, set the body to 'no docs found',\n            // Otherwise just take 1st element from the feed.\n            if (!feed || !feed.length) getContext().getResponse().setBody(\"no docs found\");\n            else getContext().getResponse().setBody(prefix + JSON.stringify(feed[0]));\n        },\n    );\n\n    if (!isAccepted) {\n        throw new Error(\n            \"The query wasn't accepted by the server. Try again/use continuation token between API and script.\",\n        );\n    }\n}\n\n/**\n * A DocumentDB stored procedure that bulk deletes documents for a given query.<br/>\n * Note: You may need to execute this sproc multiple times (depending whether the sproc is able to delete every document within the execution timeout limit).\n *\n * @param {string} query - A query that provides the documents to be deleted (e.g. \"SELECT * FROM c WHERE c.founded_year = 2008\")\n * @returns {Object.<number, boolean>} Returns an object with the two properties:<br/>\n *   deleted - contains a count of documents deleted<br/>\n *   continuation - a boolean whether you should execute the sproc again (true if there are more documents to delete; false otherwise).\n */\nfunction bulkDeleteSproc(query: string) {\n    var collection: ICollection = getContext().getCollection();\n    var collectionLink: string = collection.getSelfLink();\n    var response: IResponse = getContext().getResponse();","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/DefinitelyTyped/DefinitelyTyped/blob/8f494947aedf1aa8238676d55723ae7f62b7dd15/types/documentdb-server/documentdb-server-tests.ts#L281-L317","documentation":"Line 299 in a sample stored procedure: collection.queryDocuments(collectionLink, query, opts, cb) returns a boolean isAccepted. When the server cannot accept the query — execution budget already spent, throughput saturated, or the query would exceed the request envelope — isAccepted is false and the sproc throws 'The query wasn't accepted by the server. Try again/use continuation token between API and script.' The message itself directs the caller to re-invoke with a continuation token.","triggerScenarios":"Issuing queryDocuments when the sproc has already used most of its budget; a query over a large result set without continuation; RU contention at query submission.","commonSituations":"Bulk-read/bulk-delete sprocs that issue one big query; devs treat the first query as the only one and don't plan for continuation.","solutions":["On isAccepted=false, return a continuation token to the client and re-invoke the sproc","Pass a continuation token from requestOptions on re-invocation","Add a WHERE clause to reduce scanned documents","Retry externally with exponential backoff; raise RU/s if persistent"],"exampleFix":"// before\nif (!isAccepted) {\n  throw new Error(\"The query wasn't accepted by the server. Try again/use continuation token between API and script.\");\n}\n// after - signal continuation instead of throwing\nif (!isAccepted) {\n  getContext().getResponse().setBody({ accepted: false, continuation: currentContinuation });\n  return;\n}","handlingStrategy":"retry","validationCode":"// client side: only call when throughput headroom exists; pass last continuation\nif (hasThroughputHeadroom()) { invokeSproc(lastContinuation); } else { waitAndRetry(); }","typeGuard":"function isAcceptedBoolean(v: any): v is boolean {\n  return typeof v === 'boolean';\n}","tryCatchPattern":"if (!isAccepted) {\n  // do not throw — return continuation so client re-invokes\n  getContext().getResponse().setBody({ accepted: false, continuation: currentContinuation });\n  return;\n}","preventionTips":["Design sprocs to be re-entrant with continuation tokens","Tighten the SQL WHERE to reduce scanned documents","Retry externally with exponential backoff","Provision RU/s to match realistic load"],"tags":["cosmosdb","azure","stored-procedure","typescript","throttling","continuation"],"backgroundTag":null,"analyzedSha":"8f494947aedf1aa8238676d55723ae7f62b7dd15","analyzedAt":"2026-08-12T16:01:38.919Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}