fix: 老小程序不改端,后端兼容扫码注册(dashouzhuce/wdlyhdl)

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
XingQue
2026-07-08 18:20:45 +08:00
parent 7fe49775b9
commit e0c48073f1
4 changed files with 95 additions and 69 deletions

View File

@@ -0,0 +1,18 @@
"""老小程序兼容:统一 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)