Skip to content

Commit 08cea2b

Browse files
committed
we now wrap 412's
1 parent cd503c7 commit 08cea2b

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_deserialize.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,16 @@ def process_storage_error(storage_error) -> NoReturn: # type: ignore [misc] # p
157157
serialized = False
158158
if not storage_error.response:
159159
raise storage_error
160-
# Preserve generated exceptions for cases where remapping is not needed.
161-
# ResourceExistsError is intentionally excluded so ConditionNotMet can be remapped
162-
# to ResourceModifiedError based on x-ms-error-code.
163-
if isinstance(storage_error, (ResourceNotFoundError, ClientAuthenticationError)):
160+
# The generated layer now pre-maps 412 (Precondition Failed) responses to typed
161+
# exceptions based on the request's match condition (e.g. ResourceExistsError for
162+
# IfMissing, ResourceNotFoundError for IfPresent). Historically 412 was not
163+
# pre-mapped and always flowed through the error-code mapping below, surfacing as
164+
# ResourceModifiedError. Skip the "already serialized" shortcut for 412 so it is
165+
# re-mapped from x-ms-error-code (ConditionNotMet -> ResourceModifiedError) and the
166+
# public exception type is preserved for users.
167+
if storage_error.response.status_code != 412 and isinstance(
168+
storage_error, (ResourceNotFoundError, ClientAuthenticationError, ResourceExistsError)
169+
):
164170
serialized = True
165171
error_code = storage_error.response.headers.get("x-ms-error-code")
166172
error_message = storage_error.message

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_shared/response_handlers.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,16 @@ def process_storage_error(storage_error) -> NoReturn: # type: ignore [misc] # p
9393
)
9494
if not storage_error.response or storage_error.response.status_code in [200, 204]:
9595
raise storage_error
96-
# Preserve generated exceptions for cases where remapping is not needed.
97-
# ResourceExistsError is intentionally excluded so ConditionNotMet can be remapped
98-
# to ResourceModifiedError based on x-ms-error-code.
99-
if isinstance(
96+
# The generated layer now pre-maps 412 (Precondition Failed) responses to typed
97+
# exceptions based on the request's match condition (e.g. ResourceExistsError for
98+
# IfMissing, ResourceNotFoundError for IfPresent). Historically 412 was not
99+
# pre-mapped and always flowed through the error-code mapping below, surfacing as
100+
# ResourceModifiedError. Skip the "already serialized" shortcut for 412 so it is
101+
# re-mapped from x-ms-error-code (ConditionNotMet -> ResourceModifiedError) and the
102+
# public exception type is preserved for users.
103+
if storage_error.response.status_code != 412 and isinstance(
100104
storage_error,
101-
(PartialBatchErrorException, ClientAuthenticationError, ResourceNotFoundError),
105+
(PartialBatchErrorException, ClientAuthenticationError, ResourceNotFoundError, ResourceExistsError),
102106
):
103107
serialized = True
104108
error_code = storage_error.response.headers.get("x-ms-error-code")

0 commit comments

Comments
 (0)