| Conditions | 7 |
| Total Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | #!/usr/bin/python |
||
| 15 | def verify_status_code(request_response: requests.Response, file_name: str) -> 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 | :type file_name: str |
||
| 20 | :return: |
||
| 21 | """ |
||
| 22 | if request_response.status_code == 200: |
||
| 23 | return STATUS_CODE_OK, '' |
||
| 24 | |||
| 25 | elif request_response.status_code == 429: |
||
| 26 | if 'limit of 150 searches' in request_response.text: |
||
| 27 | raise DailyLimitReachedException('Daily search limit for unregistered users reached') |
||
|
|
|||
| 28 | elif 'limit of 300 searches' in request_response.text: |
||
| 29 | raise DailyLimitReachedException('Daily search limit for basic users reached') |
||
| 30 | else: |
||
| 31 | raise DailyLimitReachedException('Daily search limit reached') |
||
| 32 | elif request_response.status_code == 403: |
||
| 33 | raise InvalidOrWrongApiKeyException("Invalid or wrong API key") |
||
| 34 | elif request_response.status_code == 413: |
||
| 35 | msg = "Payload too large, skipping file: {0:s}".format(file_name) |
||
| 36 | return STATUS_CODE_SKIP, msg |
||
| 37 | else: |
||
| 38 | msg = "Unknown status code: {0:d}".format(request_response.status_code) |
||
| 39 | return STATUS_CODE_REPEAT, msg |
||
| 40 |