From 87659dcd3aff6dbd68a3dc007d73f8cf63dba88a Mon Sep 17 00:00:00 2001 From: Yongteng Lei Date: Tue, 14 Oct 2025 14:13:10 +0800 Subject: [PATCH] Fix: unexpected Auth return code (#10539) ### What problem does this PR solve? Fix unexpected Auth return code. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- api/utils/api_utils.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/api/utils/api_utils.py b/api/utils/api_utils.py index 1579e852b..ad78067d2 100644 --- a/api/utils/api_utils.py +++ b/api/utils/api_utils.py @@ -151,10 +151,12 @@ def get_data_error_result(code=settings.RetCode.DATA_ERROR, message="Sorry! Data def server_error_response(e): logging.exception(e) try: - if e.code == 401: - return get_json_result(code=401, message=repr(e)) - except BaseException: - pass + msg = repr(e).lower() + if getattr(e, "code", None) == 401 or ("unauthorized" in msg) or ("401" in msg): + return get_json_result(code=settings.RetCode.UNAUTHORIZED, message=repr(e)) + except Exception as ex: + logging.warning(f"error checking authorization: {ex}") + if len(e.args) > 1: try: serialized_data = serialize_for_json(e.args[1])