shijl0925 / python-sonarqube-api

Python Client library for interacting with Community, Developer, and Enterprise Editions SonarQube's REST APIs and SonarCloud's REST APIs.
https://python-sonarqube-pro-api.readthedocs.io/en/latest/
GNU Affero General Public License v3.0
133 stars 77 forks source link

Improve the reporting of a 404 response status code #28

Closed rgl closed 3 years ago

rgl commented 3 years ago

While trying to test whether a given SonarQube project already has alm settings, I'm currently doing:

c = sonarqube.SonarEnterpriseClient(sonarqube_url=sonarqube_address, token=sonarqube_api_token)
binding = c.alm_settings.get_binding(sonarqube_project_key)

When there is no alm settings defined at the project, get_binding raises a generic sonarqube.utils.exceptions.ClientError with the message Error in request. Possibly client error [404]: Project 'xxx' is not bound to any ALM.

But there is no straightforward way to deal with this expected error without looking at the exception message for Possibly client error [404].

Can we have a better way of reporting a 404?

For example, maybe with a class named NotFoundClientError?

Also, maybe add a response_code property to the ClientError class too?

shijl0925 commented 3 years ago

Thank you for your advice.

rgl commented 3 years ago

Thank you!

For reference, this was implemented in https://github.com/shijl0925/python-sonarqube-api/commit/c89f78eda3806047f5888f2b3604759fe65b2820 and released in 1.2.4.