exceptions¶
Warning
As long as major version of this library is 0 (i.e. library has version 0.x.y), API is not guaranteed to be compatible between versions. When you start using this library, please let the developer know about - I will bump the major version to 1, and usuall semver guatantees regarding version compatibility will be applied.
Overview¶
Basically, there are two main exception classes:
APIFailureException and APIErrorException.
First of them (the “failure” one) happens when API server returns something what was not expected by the library: for example, when library expects to receive a JSON, but can’t parse the response. Cases like this should not happen outside of unittests, so if you encounter one - please file an issue.
Second one (the “error” one) happens when API server returns (properly formatted) error response. In that case, it is assumed that it was a problem with how the library is used. But if you disagree - please file an issue.
Both of these classes are based on the BaseAPIException, and has
the following attributes usually set: request, response, data.
request and response link to relevant instances of
urllib.request.Request, http.client.HTTPResponse, or
urllib.error.HTTPError, if they were available at the moment when the
exception was raised. In addition to this, APIFailureException
has a message attribute, which contains a text description of the problem.
Also, there is a APIErrorFailureException, which is raised if
APIFailureException (i.e. unparsable or invalid JSON) happens.
It’s a subclass of APIFailureException, so you don’t need to
care about it, unless you’re interested in it.
Reference¶
- exception python_gtmetrix2.exceptions.BaseAPIException(request, response, data, extra=None)[source]¶
Bases:
ExceptionBase class for all exceptions in this library. Passed parameter are available as attributes.
- Parameters
request (
urllib.request.Requestor None) – Request which was sent to the API server, if available.response (
http.client.HTTPResponseorurllib.error.HTTPError) – Response from the API server.data (None, bytes or dict (in case it was parsed from JSON)) – data received from the API server, if any.
extra – extra information, if available, defaults to None.
- exception python_gtmetrix2.exceptions.APIFailureException(message, *args)[source]¶
Bases:
python_gtmetrix2.exceptions.BaseAPIExceptionAPI server returned an unexpected response.
There was a disagreement between API server and this library: server returned something what the library did not expect to receive.
- Parameters
message (str) – text explaining the error.
other parameters are same as for parent class
BaseAPIException.
- exception python_gtmetrix2.exceptions.APIErrorFailureException(message, *args)[source]¶
Bases:
python_gtmetrix2.exceptions.APIFailureExceptionAPIFailureException happened when processing an error response.
Parameters are the same as for parent class
APIFailureException.
- exception python_gtmetrix2.exceptions.APIErrorException(request, response, data, extra=None)[source]¶
Bases:
python_gtmetrix2.exceptions.BaseAPIExceptionAPI returned an error.
Parameters are the same as for parent class
BaseAPIException.You can inspect error details in the data attribute of this object, it usually looks like this:
{ "errors": [ { "status": "405", "code": "E40500", "title": "HTTP method not allowed", "detail": "Method is not supported by the endpoint" } ] }