Skip to content

Commit 7ecade7

Browse files
authored
Merge pull request #115 from TTWShell/feature/return-code-type
support HOBBIT_USE_CODE_ORIGIN_TYPE
2 parents 7df9674 + 448ec10 commit 7ecade7

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

hobbit_core/response.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from mypy_extensions import TypedDict
33

44
from flask.json import dumps
5+
from flask import current_app
56
from werkzeug import Response
67

78
RESP_MSGS = {
@@ -36,9 +37,14 @@ def gen_response(code: int, message: str = '', detail: Optional[str] = None,
3637
Returns:
3738
dict: A dict contains all args.
3839
40+
2021-06-08 Updated:
41+
Default type of `code` in response is force conversion to `str`, now
42+
support set `HOBBIT_USE_CODE_ORIGIN_TYPE = True` to return origin type.
3943
"""
44+
use_origin_type = current_app.config.get(
45+
'HOBBIT_USE_CODE_ORIGIN_TYPE', False)
4046
return {
41-
'code': str(code),
47+
'code': str(code) if use_origin_type is False else code,
4248
'message': message or RESP_MSGS.get(code, '未知错误'), # type: ignore
4349
'data': data,
4450
'detail': detail,

0 commit comments

Comments
 (0)