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

Raise an APIError for all error status codes #55

Open
KPreisner opened this issue Sep 19, 2024 · 0 comments
Open

Raise an APIError for all error status codes #55

KPreisner opened this issue Sep 19, 2024 · 0 comments

Comments

@KPreisner
Copy link
Member

if response.status_code == 401:
raise Sindri.APIError(f"401 - Invalid API Key. path={full_path}")
elif response.status_code == 404:
raise Sindri.APIError(f"404 - Not found. path={full_path}")
else:
# Decode JSON response
try:
response_json = response.json()
except json.decoder.JSONDecodeError:
raise Sindri.APIError(
f"Unexpected Error. Unable to decode response as JSON."
f" status={response.status_code} response={response.text}"
) from None
return response.status_code, response_json

Raise an APIError for all error status codes

Issue: Not all error status codes raise an exception with the status_code number in the exception string. This leads to silent failures.

Resolution: Adjust the conditional logic (linked above) to always raise an APIError with the status_code if there is an error, not just if the response cannot be decoded from JSON.

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

No branches or pull requests

1 participant