<commit_before>class RequestHandlerMiddleware():
    ''''''
    
    def process_request(self, request):
        ''''''
        pass
    
    
    def process_view(self, request, view_func, view_args, view_kwargs):
        ''''''
        pass
    
    
    def process_response(self, request, response):
        ''''''
        pass
    
    
    def process_exception(self, request, exception):
        ''''''
        pass<commit_msg>Main middleware now intercepts errors, and customizes the output in some cases.<commit_after>from nuages.http import HttpException, HttpResponse


class RequestHandlerMiddleware():
#    def process_request(self, request):
#        ''''''
#        pass
#    
#    def process_view(self, request, view_func, view_args, view_kwargs):
#        ''''''
#        pass
#    
#    def process_response(self, request, response):
#        ''''''
#        return response
    
    def process_exception(self, request, exception):
        ''''''
        if not issubclass(exception.__class__, HttpException):
            return
        
        node = exception.node
        response = HttpResponse(request, status=exception.status)
        
        if response.status_code == 405: #Method Not Allowed
            response['Allow'] = 'OPTIONS,' + ','.join(node.allows)
            
        return response
{'fraction_non_alphanumeric': 0.11840120663650075, 'fraction_numerical': 0.0022624434389140274, 'mean_word_length': 2.2604422604422605, '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': '5360141', 'n_tokens_mistral': 357, 'n_tokens_neox': 361, 'n_words': 82}