<commit_before>from rest_framework.views import exception_handler

from rest_framework_friendly_errors import settings
from rest_framework_friendly_errors.utils import is_pretty


def friendly_exception_handler(exc, context):
    response = exception_handler(exc, context)

    if response is not None:
        if is_pretty(response):
            return response
        error_message = response.data['detail']
        error_code = settings.FRIENDLY_EXCEPTION_DICT.get(
            exc.__class__.__name__)
        response.data.pop('detail', {})
        response.data['code'] = error_code
        response.data['message'] = error_message
        response.data['status_code'] = response.status_code
        # response.data['exception'] = exc.__class__.__name__

    return response
<commit_msg>Build APIException all exceptions must be handled<commit_after>from rest_framework.views import exception_handler
from rest_framework.exceptions import APIException

from rest_framework_friendly_errors import settings
from rest_framework_friendly_errors.utils import is_pretty


def friendly_exception_handler(exc, context):
    response = exception_handler(exc, context)

    if not response and settings.FRIENDLY_CATCH_ALL_EXCEPTIONS:
        response = exception_handler(APIException(exc), context)

    if response is not None:
        if is_pretty(response):
            return response
        error_message = response.data['detail']
        error_code = settings.FRIENDLY_EXCEPTION_DICT.get(
            exc.__class__.__name__)
        response.data.pop('detail', {})
        response.data['code'] = error_code
        response.data['message'] = error_message
        response.data['status_code'] = response.status_code
        # response.data['exception'] = exc.__class__.__name__

    return response

{'fraction_non_alphanumeric': 0.079312257348863, 'fraction_numerical': 0.0, 'mean_word_length': 3.7349081364829395, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4635358', 'n_tokens_mistral': 482, 'n_tokens_neox': 471, 'n_words': 104}