Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cosmos] archboard review item - update batch error description #34473

Merged
merged 7 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions sdk/cosmos/azure-cosmos/azure/cosmos/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,20 @@ def __init__(
operation_responses=None,
**kwargs):
"""
:param int error_index: Index of operation within the batch that caused the error.
:param dict[str, Any] headers: Error headers.
:param int status_code: HTTP response code.
:param str message: Error message.
:param list operation_responses: List of failed operations' responses.
:ivar int error_index: Index of operation within the batch that caused the error.
annatisch marked this conversation as resolved.
Show resolved Hide resolved
:ivar dict[str, Any] headers: Error headers.
:ivar int status_code: HTTP response code.
:ivar str message: Error message.
:ivar list operation_responses: List of failed operations' responses.
annatisch marked this conversation as resolved.
Show resolved Hide resolved
.. admonition:: Example:

.. literalinclude:: ../samples/document_management.py
:start-after: [START handle_batch_error]
:end-before: [END handle_batch_error]
:language: python
:dedent: 0
:caption: Handle a CosmosBatchOperationError:
:name: handle_batch_error
"""
self.error_index = error_index
self.headers = headers
Expand Down
2 changes: 2 additions & 0 deletions sdk/cosmos/azure-cosmos/samples/document_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ def execute_item_batch(database):

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


def delete_item(container, doc_id):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ async def execute_item_batch(database):

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


async def delete_item(container, doc_id):
Expand Down