Conditions | 8 |
Total Lines | 27 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Tests | 17 |
CRAP Score | 8.0747 |
Changes | 0 |
1 | #!/usr/bin/python |
||
15 | 1 | def verify_status_code(request_response: requests.Response) -> tuple: |
|
16 | """Verify the status code of the post request to the search url and raise exceptions if the code is unexpected |
||
17 | |||
18 | :type request_response: requests.Response |
||
19 | :return: |
||
20 | """ |
||
21 | 1 | if request_response.status_code == 200: |
|
22 | 1 | return STATUS_CODE_OK, '' |
|
23 | |||
24 | 1 | elif request_response.status_code == 429: |
|
25 | 1 | if 'user\'s rate limit' in request_response.text: |
|
26 | msg = "Search rate limit reached" |
||
27 | return STATUS_CODE_REPEAT, msg |
||
28 | 1 | if 'limit of 150 searches' in request_response.text: |
|
29 | 1 | raise DailyLimitReachedException('Daily search limit for unregistered users reached') |
|
30 | 1 | elif 'limit of 300 searches' in request_response.text: |
|
31 | 1 | raise DailyLimitReachedException('Daily search limit for basic users reached') |
|
32 | else: |
||
33 | 1 | raise DailyLimitReachedException('Daily search limit reached') |
|
34 | 1 | elif request_response.status_code == 403: |
|
35 | 1 | raise InvalidOrWrongApiKeyException("Invalid or wrong API key") |
|
36 | 1 | elif request_response.status_code == 413: |
|
37 | 1 | msg = "Payload too large, skipping file" |
|
38 | 1 | return STATUS_CODE_SKIP, msg |
|
39 | else: |
||
40 | 1 | msg = "Unknown status code: {0:d}".format(request_response.status_code) |
|
41 | return STATUS_CODE_REPEAT, msg |
||
42 |