summaryrefslogtreecommitdiff
path: root/web/apps/util/exception_handler.py
blob: a58227ad6c3c5e30292c0faf23e94d4b55fea216 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from rest_framework.views import exception_handler


def custom_exception_handler(exc, context):
    # Call REST framework's default exception handler first,
    # to get the standard error response.
    response = exception_handler(exc, context)

    # Now add the HTTP status code to the response.
    if response is not None:
        response.data['code'] = response.status_code
        response.data['desc'] = response.data['detail']
        # response.data['data'] = None #
        del response.data['detail']  # delete detail field

    return response