-
Notifications
You must be signed in to change notification settings - Fork 57
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
Support status code range for errors #2940
Comments
See microsoft/typespec#5203 (comment) for additional details |
Since python SDK has error_map predefined, we could add all the status code there. For example: for status_code in range(400, 499):
error_map.update[status_code] = cast(
Type[HttpResponseError],
lambda response: HttpResponseError(
response=response, model=_deserialize(_models.Standard4XXResponse, response.json())
),
), With this way, we don't need to change error handling logic. nit: DPG model serialize doesn't have failsafe_deserialize for now. |
it is the easiest way, but the code is so duplicate. maybe we could vendor a |
I don't understand why we're touching error_map? Error_map is to pick the exception, it's not to change the model that we deserialize. It also would overwrite what would have been passed by the caller, which we shouldn't do. I think the error_map solution is fixing it the wrong way. |
Error_map is to pick the exception, it's not to change the model that we deserialize. It also would overwrite what would have been passed by the caller, which we shouldn't do. Anyway, I think both solutions result in same behavior and @tadelesh could pick up one. |
We could also create a helper function in _vendor.py to make it more clean. For example: # operations.py
...
error_map.udpate(get_error_map({(401, 499): _models.Standard4XXResponse}, (501,599): _models.Strandard5XXResponse))
# _vendor.py
error_map = {}
def get_error_map(error_info: Dict[Tuple[int,int], Any])
for status_code_range, model_type in error_info:
for status_code in range(status_code_range[0], status_code_range[1]):
error_map[status_code] = cast(
Type[HttpResponseError],
lambda response: HttpResponseError(
response=response, model=_deserialize(model_type, response.json())
),
), |
in current sdk, we use |
1. add ranged status code support for exception 2. move customized exception handling logic from error map to exception handling 3. add `_failsafe_deserialize` function to provide fail saft deserialization for exception to support always return http response exception fix: Azure/autorest.python#2937 fix: Azure/autorest.python#2940
1. add ranged status code support for exception 2. move customized exception handling logic from error map to exception handling 3. add `_failsafe_deserialize` function to provide fail saft deserialization for exception to support always return http response exception fix: Azure/autorest.python#2937 fix: Azure/autorest.python#2940
Example for TypeSpec like:
We should generate the code:
It should be for both unbranded and Azure, as a fundational feature of our codegen
The text was updated successfully, but these errors were encountered: