This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomRenderer(JSONRenderer): | |
def render(self, data, accepted_media_type=None, renderer_context=None): | |
if data is None: | |
return bytes() | |
renderer_context = renderer_context or {} | |
indent = self.get_indent(accepted_media_type, renderer_context) | |
new_data = { # new expose | |
'code': None, | |
'message': '', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework.views import exception_handler | |
from rest_framework.exceptions import ErrorDetail | |
def custom_exception_handler(exc, context): | |
if hasattr(exc, 'detail'): | |
if isinstance(exc.detail, ErrorDetail): | |
context['kwargs']['message'] = exc.detail.title() | |
else: | |
t = exc.get_full_details().popitem() |