(f)
return _inner
Generic decorator to return better notice/message about why the authentication failed. Currently taking care of
    only basic auth for inactive or deleted mobile user but should/can be extended for other auth methods and cases
    :return json response with apt error_code in app_string and default response in english for missing
    translations and status_code as 406(unacceptable), similar code needed different from 401
Generic decorator to return better notice/message about why the authentication failed. Currently taking care of
    only basic auth for inactive or deleted mobile user but should/can be extended for other auth methods and cases
    :return json response with apt error_code in app_string and default response in english for missing
    translations and status_code as 406(unacceptable), similar code needed different from 401
Generic decorator to return better notice / message about why the authentication failed . Currently taking care of only basic auth for inactive or deleted mobile user but should / can be extended for other auth methods and cases : return json response with apt error_code in app_string and default response in english for missing translations and status_code as 406 ( unacceptable ) similar code needed different from 401
def handle_401_response(f):
    """
    Generic decorator to return better notice/message about why the authentication failed. Currently taking care of
    only basic auth for inactive or deleted mobile user but should/can be extended for other auth methods and cases
    :return json response with apt error_code in app_string and default response in english for missing
    translations and status_code as 406(unacceptable), similar code needed different from 401
    """
    @wraps(f)
    def _inner(request, domain, *args, **kwargs):
        response = f(request, domain, *args, **kwargs)
        if response.status_code == 401:
            auth_type = determine_authtype_from_request(request)
            if auth_type and auth_type == 'basic':
                username, _ = get_username_and_password_from_request(request)
                if username:
                    valid, message, error_code = ensure_active_user_by_username(username)
                    if not valid:
                        return json_response({
                            "error": error_code,
                            "default_response": message
                        }, status_code=406)

        return response
    return _inner
def handle_401_response ( f ) : @ wraps ( f ) def _inner ( request , domain , * args , * * kwargs ) : response = f ( request , domain , * args , * * kwargs ) if response . status_code == 401 : auth_type = determine_authtype_from_request ( request ) if auth_type and auth_type == 'basic' : username , _ = get_username_and_password_from_request ( request ) if username : valid , message , error_code = ensure_active_user_by_username ( username ) if not valid : return json_response ( { "error" : error_code , "default_response" : message } , status_code = 406 ) return response return _inner