

def json_api_exception_handler(exc, context):
    '\n    Custom exception handler that returns errors object as an array\n    '
    from rest_framework.views import exception_handler
    response = exception_handler(exc, context)
    errors = []
    if response:
        message = response.data
        if isinstance(exc, TwoFactorRequiredError):
            response['X-OSF-OTP'] = 'required; app'
        if isinstance(exc, JSONAPIException):
            errors.extend([{
                'source': (exc.source or {
                    
                }),
                'detail': exc.detail,
                'meta': (exc.meta or {
                    
                }),
            }])
        elif isinstance(message, dict):
            errors.extend(dict_error_formatting(message, None))
        else:
            if isinstance(message, basestring):
                message = [message]
            for (index, error) in enumerate(context):
                if isinstance(error, dict):
                    errors.extend(dict_error_formatting(error, index))
                else:
                    errors.append({
                        'detail': error,
                    })
        response.data = {
            'errors': errors,
        }
    return response

dataset/ETHPy150Open CenterForOpenScience/osf.io/api/base/exceptions.py json_api_exception_handler/VarMisuse@174/238 `message`->`context`