Files
Django/jituan/services/api_compat.py

19 lines
666 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""老小程序兼容:统一 JSON 错误格式(勿改前端时靠后端适配)。"""
from rest_framework import status
from rest_framework.response import Response
def legacy_miniapp_error(code, message, http_status=status.HTTP_200_OK):
"""
业务错误返回 HTTP 200 + body.code。
老端 request.js 会把 HTTP 403 当成「请先登录」,导致只显示「注册失败」。
同时写 message 与 msg兼容 dashouzhuce / wdlyhdl 两种字段名。
"""
text = message or '操作失败'
return Response({
'code': code,
'message': text,
'msg': text,
'data': None,
}, status=http_status)