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

feat: improve aiohttp client error messages #1201

Merged
merged 10 commits into from
Dec 3, 2024
Merged

Conversation

jackwotherspoon
Copy link
Collaborator

@jackwotherspoon jackwotherspoon commented Nov 27, 2024

By default, aiohttp on bad requests will discard response body and
output generic error message in response, Bad Request, Forbidden, etc.

The Cloud SQL Admin APIs response body contains more detailed error messages.
We need to raise these to the end user for them to be able to resolve common config
issues on their own.

In #362 we caught 403 errors and implemented a custom error message
to point users at the most common config issues, Cloud SQL API not being enabled,
missing Cloud SQL Client role etc. However, this was not a catch-all (as noted by #1199)
and more of a temporary fix.

This PR implements a more robust solution, copying the actual Cloud SQL Admin API
response body's error message to the end user.

Note

Example common scenario: Calling the Python Connector with a typo in your instance name.

Old Error Message:

aiohttp.client_exceptions.ClientResponseError: 404, message='Not Found'

New Error Message after PR:

aiohttp.client_exceptions.ClientResponseError: 404, message='The Cloud SQL instance does not exist.'

Related aio-libs/aiohttp#4600
I looked into using a custom response class but it seemed over the top
compared to the working approach here.

Closes #477

@jackwotherspoon jackwotherspoon self-assigned this Nov 27, 2024
@jackwotherspoon jackwotherspoon requested a review from a team as a code owner November 27, 2024 02:47
rhatgadkar-goog added a commit to GoogleCloudPlatform/alloydb-python-connector that referenced this pull request Dec 3, 2024
This change is similar to
GoogleCloudPlatform/cloud-sql-python-connector#1201,
except for AlloyDB.

In short, we want to use the AlloyDB API's response body for error
messages, because they are more detailed.
Copy link

@rhatgadkar-goog rhatgadkar-goog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found some issues with the unit tests when I was implementing this change for AlloyDB.

@GoogleCloudPlatform GoogleCloudPlatform deleted a comment from al0932 Dec 3, 2024
@jackwotherspoon
Copy link
Collaborator Author

I found some issues with the unit tests when I was implementing this change for AlloyDB.

@rhatgadkar-goog Moved asserts out of pytest.raises block 😄

@jackwotherspoon jackwotherspoon merged commit 11f9fe9 into main Dec 3, 2024
14 checks passed
@jackwotherspoon jackwotherspoon deleted the client-errors branch December 3, 2024 21:05
rhatgadkar-goog added a commit to GoogleCloudPlatform/alloydb-python-connector that referenced this pull request Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve aiohttp error handling by converting response body to error
3 participants