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 | ||||
from typing import Any, Optional | |||||
class InvalidObjectType(TypeError): | class InvalidObjectType(TypeError): | ||||
pass | pass | ||||
class InvalidDirectoryPath(Exception): | class InvalidDirectoryPath(Exception): | ||||
pass | pass | ||||
class LargePayloadExc(Exception): | class LargePayloadExc(Exception): | ||||
pass | pass | ||||
class DBError(Exception): | class DBError(Exception): | ||||
pass | pass | ||||
class APIError(Exception): | class APIError(Exception): | ||||
def __str__(self): | def __str__(self): | ||||
return '"%s"' % self.args | return '"%s"' % self.args | ||||
def error_response(reason: str, status_code: int, api_url: str): | def error_response(reason: Optional[Any], status_code: int, api_url: str): | ||||
error_msg = f"{status_code} {reason}: '{api_url}'" | error_msg = f"{status_code} {reason}: '{api_url}'" | ||||
raise APIError(error_msg) | raise APIError(error_msg) |