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

Any way to get the http response status_code #2579

Open
alfie80 opened this issue May 8, 2024 · 3 comments
Open

Any way to get the http response status_code #2579

alfie80 opened this issue May 8, 2024 · 3 comments
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@alfie80
Copy link

alfie80 commented May 8, 2024

Currently the generated code will return the deserialized response.json() which contains the response body only. Is there any way to return the status_code to the user as well?

image

@microsoft-github-policy-service microsoft-github-policy-service bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels May 8, 2024
@iscai-msft
Copy link
Contributor

Yes, you can use the raw_response_hook, and pass in a callback. Within that callback you get access to the whole pipeline_response, giving you access to status_code. Here is a code snippet you can follow.

If this helps you out, you can close the issue. Thanks so much for reaching out!

@alfie80
Copy link
Author

alfie80 commented May 10, 2024

Yes, you can use the raw_response_hook, and pass in a callback. Within that callback you get access to the whole pipeline_response, giving you access to status_code. Here is a code snippet you can follow.

If this helps you out, you can close the issue. Thanks so much for reaching out!

Thank you @iscai-msft for your reply. I can now get the status_code in this way. But it seems difficult to make it safe in async or multi-thread use cases and the ideal way I think is to return it as an attribute of the response object. (just like @azure-tools/typespec-ts does - see below screenshots)

image
image

@iscai-msft
Copy link
Contributor

@alfie80 I understand the difficulty, this was a design choice we made a while back. While other languages would return a response of T, we would just return T, and if you wanted more response information, you would have to access through callback since it wasn't the main scenario.

I'm tagging @johanste the architect of the Python SDK for any more input / questions

Could you also go more into the use case of accessing the status code? There are options where you can customize the generated code to change this behavior if you expect the users of your SDK to care more about this information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

No branches or pull requests

2 participants