This PR refactors the _handle_request method in the BaseAPI class to improve reliability, exception management, and logging efficiency. The changes ensure that the API client behaves more predictably under failure conditions and performs better in logging operations.
Details
Added a timeout argument to the requests.request method to avoid indefinite hangs.
Improved exception handling by capturing and raising specific exceptions (ConnectTimeout, ConnectionError) to provide clearer error feedback during network issues.
Introduced lazy string interpolation using % formatting for logging within the _handle_request method to enhance performance and prevent premature string formatting.
Enhanced the API response parsing method for cleaner handling of status codes.
Fixed an issue with _url() method where it referenced an incorrect base URL variable.
Description
This PR refactors the
_handle_request
method in the BaseAPI class to improve reliability, exception management, and logging efficiency. The changes ensure that the API client behaves more predictably under failure conditions and performs better in logging operations.Details
requests.request
method to avoid indefinite hangs.ConnectTimeout
,ConnectionError
) to provide clearer error feedback during network issues.%
formatting for logging within the_handle_request
method to enhance performance and prevent premature string formatting._url()
method where it referenced an incorrect base URL variable.