Skip to content

Raise an APIError for all error status codes  #55

Description

@KPreisner

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions