Closed seasonedfish closed 2 years ago
Hmm, another option is to define a new exception APIError
, that way applications calling sec-api can catch that specific one instead of Exception
. (From stack overflow)
This also simplifies the code, because you can write it like this:
@@ -30,10 +34,10 @@ class QueryApi:
# wait 500 * (x + 1) milliseconds and try again
time.sleep(0.5 * (x + 1))
else:
- raise Exception("API error: " + str(response.status_code))
+ raise APIError(response.status_code)
else:
# request failed
- raise Exception("API error")
+ raise APIError
When sec_api tries to raise an exception, it causes a TypeError:
Since
response.status_code
is an int, it cannot be concatenated to the preceding string. This can be fixed by castingresponse.status_code
to a string.