Добавлены классы ответов
This commit is contained in:
40
net/xeaf/rack/models/responses/exception_response.py
Normal file
40
net/xeaf/rack/models/responses/exception_response.py
Normal file
@@ -0,0 +1,40 @@
|
||||
# DRF Rack
|
||||
# Библиотека классов расширений для Django REST Framework
|
||||
#
|
||||
# Автор: Николай В. Анохин <n.anokhin@xeaf.net>
|
||||
# Все права защищены. Лицензия: MIT
|
||||
|
||||
"""
|
||||
Описание класса ExceptionResponse
|
||||
"""
|
||||
|
||||
from rest_framework import status
|
||||
|
||||
from net.xeaf.rack.core import CoreException
|
||||
from net.xeaf.rack.core import CoreResponse
|
||||
|
||||
|
||||
class ExceptionResponse(CoreResponse):
|
||||
"""
|
||||
Ответ с информацией об исключении
|
||||
"""
|
||||
|
||||
def __init__(self, exc: CoreException, meta: dict | None = None):
|
||||
"""
|
||||
Инициализация
|
||||
|
||||
:param exc: Исключение
|
||||
:param meta: Дополнительная информация
|
||||
"""
|
||||
|
||||
# Проверяем требование передать реальный статус
|
||||
if exc.is_pure_status():
|
||||
external_status = exc.status_code
|
||||
else:
|
||||
external_status = status.HTTP_200_OK
|
||||
|
||||
super(ExceptionResponse, self).__init__(
|
||||
internal_status=exc.status_code,
|
||||
external_status=external_status,
|
||||
data=exc.detail,
|
||||
meta=meta)
|
||||
Reference in New Issue
Block a user