from rest_framework.exceptions import APIException from rest_framework import status class ExternalAPIError(APIException): """外部 API 调用错误""" status_code = status.HTTP_500_INTERNAL_SERVER_ERROR default_detail = '外部 API 调用失败' default_code = 'external_api_error' def __init__(self, detail=None, code=None): if detail is None: detail = self.default_detail if code is None: code = self.default_code super().__init__(detail, code)