Skip to content

Commit 863ccdd

Browse files
authored
[Cosmos] archboard review item - update batch error description (#34473)
* update batch error description * Revert "update batch error description" This reverts commit 9fbe949. * linked sample, updated ivar * Update exceptions.py * Update exceptions.py * Update exceptions.py * Update exceptions.py
1 parent 07995c5 commit 863ccdd

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

sdk/cosmos/azure-cosmos/azure/cosmos/exceptions.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,27 @@ class CosmosAccessConditionFailedError(CosmosHttpResponseError):
6666

6767

6868
class CosmosBatchOperationError(HttpResponseError):
69-
"""A transactional batch request to the Azure Cosmos database service has failed."""
70-
69+
"""A transactional batch request to the Azure Cosmos database service has failed.
70+
71+
:ivar int error_index: Index of operation within the batch that caused the error.
72+
:ivar headers: Error headers.
73+
:vartype headers: dict[str, Any]
74+
:ivar status_code: HTTP response code.
75+
:vartype status_code: int
76+
:ivar message: Error message.
77+
:vartype message: str
78+
:ivar operation_responses: List of failed operations' responses.
79+
:vartype operation_responses: List[dict[str, Any]]
80+
.. admonition:: Example:
81+
82+
.. literalinclude:: ../samples/document_management.py
83+
:start-after: [START handle_batch_error]
84+
:end-before: [END handle_batch_error]
85+
:language: python
86+
:dedent: 0
87+
:caption: Handle a CosmosBatchOperationError:
88+
:name: handle_batch_error
89+
"""
7190
def __init__(
7291
self,
7392
error_index=None,
@@ -76,13 +95,6 @@ def __init__(
7695
message=None,
7796
operation_responses=None,
7897
**kwargs):
79-
"""
80-
:param int error_index: Index of operation within the batch that caused the error.
81-
:param dict[str, Any] headers: Error headers.
82-
:param int status_code: HTTP response code.
83-
:param str message: Error message.
84-
:param list operation_responses: List of failed operations' responses.
85-
"""
8698
self.error_index = error_index
8799
self.headers = headers
88100
self.sub_status = None

sdk/cosmos/azure-cosmos/samples/document_management.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ def execute_item_batch(database):
243243

244244
# For error handling, you should use try/ except with CosmosBatchOperationError and use the information in the
245245
# error returned for your application debugging, making it easy to pinpoint the failing operation
246+
# [START handle_batch_error]
246247
batch_operations = [create_item_operation, create_item_operation]
247248
try:
248249
container.execute_item_batch(batch_operations, partition_key="Account1")
@@ -251,6 +252,7 @@ def execute_item_batch(database):
251252
error_operation_response = e.operation_responses[error_operation_index]
252253
error_operation = batch_operations[error_operation_index]
253254
print("\nError operation: {}, error operation response: {}\n".format(error_operation, error_operation_response))
255+
# [END handle_batch_error]
254256

255257

256258
def delete_item(container, doc_id):

sdk/cosmos/azure-cosmos/samples/document_management_async.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ async def execute_item_batch(database):
262262

263263
# For error handling, you should use try/ except with CosmosBatchOperationError and use the information in the
264264
# error returned for your application debugging, making it easy to pinpoint the failing operation
265+
# [START handle_batch_error]
265266
batch_operations = [create_item_operation, create_item_operation]
266267
try:
267268
await container.execute_item_batch(batch_operations, partition_key="Account1")
@@ -270,6 +271,7 @@ async def execute_item_batch(database):
270271
error_operation_response = e.operation_responses[error_operation_index]
271272
error_operation = batch_operations[error_operation_index]
272273
print("\nError operation: {}, error operation response: {}\n".format(error_operation, error_operation_response))
274+
# [END handle_batch_error]
273275

274276

275277
async def delete_item(container, doc_id):

0 commit comments

Comments
 (0)