Skip to content

Commit 453eb7c

Browse files
aditishree1Aditishree .
andauthored
[cosmos] Fix bulk error response (Azure#34294)
### Packages impacted by this PR @azure/cosmos ### Issues associated with this PR ### Describe the problem that is addressed by this PR This PR fixes some parsing errors in the bulk response. ### What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen? ### Are there test cases added in this PR? _(If not, why?)_ ### Provide a list of related PRs _(if any)_ ### Command used to generate this PR:**_(Applicable only to SDK release request PRs)_ ### Checklists - [ ] Added impacted package name to the issue description - [ ] Does this PR needs any fixes in the SDK Generator?** _(If so, create an Issue in the [Autorest/typescript](https://github.com/Azure/autorest.typescript) repository and link it here)_ - [ ] Added a changelog (if necessary) --------- Co-authored-by: Aditishree . <[email protected]>
1 parent 47033fd commit 453eb7c

File tree

6 files changed

+27
-14
lines changed

6 files changed

+27
-14
lines changed

sdk/cosmosdb/cosmos/review/cosmos.api.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ export const Constants: {
531531
Location: string;
532532
Referer: string;
533533
A_IM: string;
534-
PREFER_RETURN_MINIMAL: string;
534+
PreferReturnMinimal: string;
535535
Query: string;
536536
IsQuery: string;
537537
IsQueryPlan: string;
@@ -1136,25 +1136,17 @@ export interface ErrorBody {
11361136
message: string;
11371137
}
11381138

1139-
// @public (undocumented)
1139+
// @public
11401140
export class ErrorResponse extends Error {
1141-
// (undocumented)
11421141
[key: string]: any;
1143-
// (undocumented)
11441142
activityId?: string;
1145-
// (undocumented)
11461143
body?: ErrorBody;
1147-
// (undocumented)
11481144
code?: number | string;
1149-
// (undocumented)
11501145
diagnostics?: CosmosDiagnostics;
1151-
// (undocumented)
11521146
headers?: CosmosHeaders;
1153-
// (undocumented)
1147+
requestCharge?: number;
11541148
retryAfterInMilliseconds?: number;
1155-
// (undocumented)
11561149
retryAfterInMs?: number;
1157-
// (undocumented)
11581150
substatus?: number;
11591151
}
11601152

sdk/cosmosdb/cosmos/src/bulk/BulkResponse.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,12 @@ export class BulkResponse {
116116
const error: ErrorResponse = new ErrorResponse();
117117
error.code = itemResponse?.statusCode;
118118
error.substatus = itemResponse?.subStatusCode;
119+
error.message = itemResponse?.message;
120+
error.requestCharge = itemResponse?.requestCharge;
119121
error.body = itemResponse?.resourceBody;
120122
error.headers = responseMessage.headers;
121123
error.activityId = responseMessage.headers?.[Constants.HttpHeaders.ActivityId];
122-
error.retryAfterInMs = itemResponse?.retryAfter;
124+
error.retryAfterInMs = itemResponse?.retryAfterMilliseconds;
123125
error.diagnostics = responseMessage.diagnostics;
124126
results.push(error);
125127
}
@@ -167,6 +169,7 @@ export class BulkResponse {
167169
errorResponse.body = error.body;
168170
errorResponse.diagnostics = error.diagnostics;
169171
errorResponse.headers = this.headers;
172+
errorResponse.requestCharge = error.requestCharge;
170173
return errorResponse;
171174
});
172175
}

sdk/cosmosdb/cosmos/src/bulk/Limiter.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ export class LimiterQueue {
148148
this.terminated = true;
149149
this.terminatedValue = customValue;
150150
const operationsList: ItemOperation[] = [];
151+
if (this.tasks.isEmpty()) {
152+
return;
153+
}
151154
while (!this.tasks.isEmpty()) {
152155
const queueItem = this.tasks.shift();
153156
if (!queueItem) break;

sdk/cosmosdb/cosmos/src/common/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export const Constants = {
6161
Location: "Location",
6262
Referer: "referer",
6363
A_IM: "A-IM",
64-
PREFER_RETURN_MINIMAL: "return=minimal",
64+
PreferReturnMinimal: "return=minimal",
6565

6666
// Query
6767
Query: "x-ms-documentdb-query",

sdk/cosmosdb/cosmos/src/request/ErrorResponse.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,29 @@ export interface GroupByAliasToAggregateType {
9494
[key: string]: AggregateType;
9595
}
9696

97+
/**
98+
* Represents an error response returned in operations.
99+
*/
97100
export class ErrorResponse extends Error {
101+
/** status or error code returned */
98102
code?: number | string;
103+
/** substatus code returned */
99104
substatus?: number;
105+
/** body of the error response, typically including error details */
100106
body?: ErrorBody;
107+
/** HTTP headers */
101108
headers?: CosmosHeaders;
109+
/** unique identifier for the operation's activity */
102110
activityId?: string;
111+
/** delay (in milliseconds) before retrying the operation. */
103112
retryAfterInMs?: number;
113+
/** delay (in milliseconds) before retrying the operation. */
114+
/** Note: Use retryAfterInMs instead */
104115
retryAfterInMilliseconds?: number;
116+
/** any additional property */
105117
[key: string]: any;
118+
/** Detailed diagnostic information associated with the error.*/
106119
diagnostics?: CosmosDiagnostics;
120+
/** The request charge of the operation, representing the resource cost incurred.*/
121+
requestCharge?: number;
107122
}

sdk/cosmosdb/cosmos/src/request/request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ export async function getHeaders({
260260
!options.contentResponseOnWriteEnabled
261261
) {
262262
if (operationType === OperationType.Batch) {
263-
headers[Constants.HttpHeaders.Prefer] = Constants.HttpHeaders.PREFER_RETURN_MINIMAL;
263+
headers[Constants.HttpHeaders.Prefer] = Constants.HttpHeaders.PreferReturnMinimal;
264264
} else {
265265
throw new ErrorResponse(
266266
"Currently `contentResponseOnWriteEnabled` option is only supported for batch and bulk operations.",

0 commit comments

Comments
 (0)