def METHOD_NAME(code, exception):
    if exception.args and isinstance(exception.args[0], bytes):
        message = exception.args[0].decode('utf-8')
    else:
        message = str(exception)
    data = {
        'error': code,
        'message': message
    }
    if code == 500 and settings.DEBUG:
        data['traceback'] = traceback.format_exc()
    return data