Fix basedpyright type errors (#25435)
Signed-off-by: -LAN- <laipz8200@outlook.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -69,6 +69,8 @@ def register_external_error_handlers(api: Api):
|
||||
headers["WWW-Authenticate"] = 'Bearer realm="api"'
|
||||
return data, status_code, headers
|
||||
|
||||
_ = handle_http_exception
|
||||
|
||||
@api.errorhandler(ValueError)
|
||||
def handle_value_error(e: ValueError):
|
||||
got_request_exception.send(current_app, exception=e)
|
||||
@@ -76,6 +78,8 @@ def register_external_error_handlers(api: Api):
|
||||
data = {"code": "invalid_param", "message": str(e), "status": status_code}
|
||||
return data, status_code
|
||||
|
||||
_ = handle_value_error
|
||||
|
||||
@api.errorhandler(AppInvokeQuotaExceededError)
|
||||
def handle_quota_exceeded(e: AppInvokeQuotaExceededError):
|
||||
got_request_exception.send(current_app, exception=e)
|
||||
@@ -83,15 +87,17 @@ def register_external_error_handlers(api: Api):
|
||||
data = {"code": "too_many_requests", "message": str(e), "status": status_code}
|
||||
return data, status_code
|
||||
|
||||
_ = handle_quota_exceeded
|
||||
|
||||
@api.errorhandler(Exception)
|
||||
def handle_general_exception(e: Exception):
|
||||
got_request_exception.send(current_app, exception=e)
|
||||
|
||||
status_code = 500
|
||||
data: dict[str, Any] = getattr(e, "data", {"message": http_status_message(status_code)})
|
||||
data = getattr(e, "data", {"message": http_status_message(status_code)})
|
||||
|
||||
# 🔒 Normalize non-mapping data (e.g., if someone set e.data = Response)
|
||||
if not isinstance(data, Mapping):
|
||||
if not isinstance(data, dict):
|
||||
data = {"message": str(e)}
|
||||
|
||||
data.setdefault("code", "unknown")
|
||||
@@ -101,10 +107,12 @@ def register_external_error_handlers(api: Api):
|
||||
exc_info: Any = sys.exc_info()
|
||||
if exc_info[1] is None:
|
||||
exc_info = None
|
||||
current_app.log_exception(exc_info) # ty: ignore [invalid-argument-type]
|
||||
current_app.log_exception(exc_info)
|
||||
|
||||
return data, status_code
|
||||
|
||||
_ = handle_general_exception
|
||||
|
||||
|
||||
class ExternalApi(Api):
|
||||
_authorizations = {
|
||||
|
||||
Reference in New Issue
Block a user