fix(http-client-python): raise azure-core error types for customized errors covering standard status codes#10998
Conversation
commit: |
|
All changed packages have been documented.
Show changes
|
|
You can try these changes here
|
iscai-msft
left a comment
There was a problem hiding this comment.
I think this is too complicated, we can just make sure we still generate the error map like here. map_error should handle throwing the correct error bc it takes in the error map that we pass it, so we don't need to specifically raise ResourceNotFoundError etc later in the code. Then keep the part that make sure the deserialization model correctly maps to the status code, like in the generated code here.
…errors covering standard status codes Always populate the operation error_map with the standard azure-core error types (401 -> ClientAuthenticationError, 404 -> ResourceNotFoundError, 409 -> ResourceExistsError, 304 -> ResourceNotModifiedError), even when a customized error model covers those status codes via a ranged or default error response. map_error then raises the dedicated error type instead of falling back to a generic HttpResponseError. The customized error body continues to be deserialized and attached to the HttpResponseError raised for other (non-standard) status codes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
57cf0b7 to
5a0ec04
Compare
If error_map has the error then doesn't map_error raise before we deserialize the body |
Problem
When a TypeSpec operation declares a customized error model that covers one of the standard azure-core status codes (401, 404, 409, 304), the Python emitter did not always raise the dedicated azure-core error type:
4XX) covering a standard code → fell through to a genericHttpResponseError.map_error) but without the deserialized error body.Fix
For status codes
401 → ClientAuthenticationError,404 → ResourceNotFoundError,409 → ResourceExistsError,304 → ResourceNotModifiedError, the generated client now deserializes the customized error body first and then raises the dedicated azure-core error type with that body attached.error_map(somap_errordoesn't pre-empt), deserialize the default body, then raise the typed error with the body. Codes already handled inline by a non-default error are skipped to avoid dead code.Example generated output (ranged + default)
Validation
response-status-code-rangemock-api tests pass (sync + async, 4/4), exercising both an in-range code and the single 404 →ResourceNotFoundErrorwith the custom body.fixchangelog entry for@typespec/http-client-python.