mirror of
https://github.com/Evil0ctal/Douyin_TikTok_Download_API.git
synced 2025-04-23 05:24:26 +08:00
106 lines
3.2 KiB
Python
106 lines
3.2 KiB
Python
# ==============================================================================
|
||
# 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]}."
|