Changeset View
Changeset View
Standalone View
Standalone View
swh/scanner/exceptions.py
# Copyright (C) 2020 The Software Heritage developers | # Copyright (C) 2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
class APIError(Exception): | class APIError(Exception): | ||||
def __str__(self): | def __str__(self): | ||||
return 'API Error: "%s"' % self.args | return '"%s"' % self.args | ||||
status_code_msg = { | |||||
404: 'Resource not found', | |||||
413: 'Payload Too Large', | |||||
429: 'Too many request', | |||||
vlorentz: nitpick: inconsistent casing, and s/request/requests/ | |||||
} | |||||
def error_response(status_code: int, api_url: str): | |||||
error_msg = f'{status_code} {status_code_msg[status_code]}: \'{api_url}\'' | |||||
vlorentzUnsubmitted Not Done Inline ActionsYou can probably use resp.reason instead of status_code_msg[resp.status] vlorentz: You can probably use `resp.reason` instead of `status_code_msg[resp.status]` | |||||
raise APIError(error_msg) |
nitpick: inconsistent casing, and s/request/requests/