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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

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.

Error Message today:

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

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
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
1 participant