Spaces:
Paused
Paused
File size: 3,280 Bytes
4be1dd5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# ==============================================================================
# Copyright (C) 2021 Evil0ctal
#
# This file is part of the Douyin_TikTok_Download_API project.
#
# This project is licensed under the Apache License 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
# __
# /> フ
# | _ _ l
# /` ミ_xノ
# / | Feed me Stars ⭐ ️
# / ヽ ノ
# │ | | |
# / ̄| | | |
# | ( ̄ヽ__ヽ_)__)
# \二つ
# ==============================================================================
#
# Contributor Link:
# - https://github.com/Evil0ctal
# - https://github.com/Johnserf-Seed
#
# ==============================================================================
class APIError(Exception):
"""基本API异常类,其他API异常都会继承这个类"""
def __init__(self, status_code=None):
self.status_code = status_code
print(
"程序出现异常,请检查错误信息。"
)
def display_error(self):
"""显示错误信息和状态码(如果有的话)"""
return f"Error: {self.args[0]}." + (
f" Status Code: {self.status_code}." if self.status_code else ""
)
class APIConnectionError(APIError):
"""当与API的连接出现问题时抛出"""
def display_error(self):
return f"API Connection Error: {self.args[0]}."
class APIUnavailableError(APIError):
"""当API服务不可用时抛出,例如维护或超时"""
def display_error(self):
return f"API Unavailable Error: {self.args[0]}."
class APINotFoundError(APIError):
"""当API端点不存在时抛出"""
def display_error(self):
return f"API Not Found Error: {self.args[0]}."
class APIResponseError(APIError):
"""当API返回的响应与预期不符时抛出"""
def display_error(self):
return f"API Response Error: {self.args[0]}."
class APIRateLimitError(APIError):
"""当达到API的请求速率限制时抛出"""
def display_error(self):
return f"API Rate Limit Error: {self.args[0]}."
class APITimeoutError(APIError):
"""当API请求超时时抛出"""
def display_error(self):
return f"API Timeout Error: {self.args[0]}."
class APIUnauthorizedError(APIError):
"""当API请求由于授权失败而被拒绝时抛出"""
def display_error(self):
return f"API Unauthorized Error: {self.args[0]}."
class APIRetryExhaustedError(APIError):
"""当API请求重试次数用尽时抛出"""
def display_error(self):
return f"API Retry Exhausted Error: {self.args[0]}."
|