aicheckv2-api/utils/response.py
2025-04-11 08:54:28 +08:00

33 lines
930 B
Python
Raw Permalink 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.

# 依赖安装pip install orjson
from fastapi.responses import ORJSONResponse as Response
from fastapi import status as http_status
from utils import status as http
class SuccessResponse(Response):
"""
成功响应
"""
def __init__(self, data=None, msg="success", code=http.HTTP_SUCCESS, status=http_status.HTTP_200_OK, **kwargs):
self.data = {
"code": code,
"message": msg,
"data": data
}
self.data.update(kwargs)
super().__init__(content=self.data, status_code=status)
class ErrorResponse(Response):
"""
失败响应
"""
def __init__(self, msg=None, code=http.HTTP_ERROR, status=http_status.HTTP_200_OK, **kwargs):
self.data = {
"code": code,
"message": msg,
"data": []
}
self.data.update(kwargs)
super().__init__(content=self.data, status_code=status)