Skip to content

Instantly share code, notes, and snippets.

View zarinpy's full-sized avatar
💭
I may be slow to respond.

omid Zarinmahd Ziaabadi zarinpy

💭
I may be slow to respond.
View GitHub Profile
@zarinpy
zarinpy / cudstom_exception_handler.py
Last active October 6, 2019 07:49
custom exception ahndler for django rest-framework
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()
@zarinpy
zarinpy / custom_renderer.py
Last active March 4, 2020 13:40
custom renderer for DRF
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': '',