fix: 老小程序不改端,后端兼容扫码注册(dashouzhuce/wdlyhdl)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
18
jituan/services/api_compat.py
Normal file
18
jituan/services/api_compat.py
Normal 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)
|
||||
Reference in New Issue
Block a user