Update po files
[mailman-postorious.git] / src / postorius / middleware.py
blob4458704eccde5946231cb30c10e52a633d24023d
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2015-2019 by the Free Software Foundation, Inc.
4 # This file is part of Postorius.
6 # Postorius is free software: you can redistribute it and/or modify it under
7 # the terms of the GNU General Public License as published by the Free
8 # Software Foundation, either version 3 of the License, or (at your option)
9 # any later version.
11 # Postorius is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 # more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Postorius. If not, see <http://www.gnu.org/licenses/>.
20 import logging
21 from urllib.error import HTTPError
23 from mailmanclient import MailmanConnectionError
25 from postorius import utils
26 from postorius.models import MailmanApiError
29 logger = logging.getLogger('postorius')
32 __all__ = [
33 'PostoriusMiddleware',
37 class PostoriusMiddleware(object):
39 def __init__(self, get_response=None):
40 self.get_response = get_response
42 def __call__(self, request):
43 return self.get_response(request)
45 def process_exception(self, request, exception):
46 if isinstance(exception, (MailmanApiError, MailmanConnectionError)):
47 logger.exception('Mailman REST API not available')
48 return utils.render_api_error(request)
49 elif isinstance(exception, HTTPError):
50 logger.exception('Un-handled exception: %s', str(exception))
51 return utils.render_client_error(request, exception)