Project

General

Profile

0001-fargo-do-not-log-403-response-as-errors-35352.patch

Benjamin Dauvergne, 10 Aug 2019 11:58 AM

Download (2.25 KB)

View differences:

Subject: [PATCH] fargo: do not log 403 response as errors (#35352)

 combo/apps/fargo/models.py | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
combo/apps/fargo/models.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
import logging
18

  
17 19
from django.conf import settings
18 20
from django.db import models
19 21
from django.forms import models as model_forms
......
25 27
from combo.utils import requests
26 28

  
27 29

  
30
logger = logging.getLogger(__name__)
31

  
32

  
28 33
@register_cell_class
29 34
class RecentDocumentsCell(CellBase):
30 35
    template_name = 'combo/fargo/recent-documents-cell.html'
......
62 67
        return hasattr(settings, 'KNOWN_SERVICES') and settings.KNOWN_SERVICES.get('fargo')
63 68

  
64 69
    def get_json(self, path, context):
65
        remote_service = get_fargo_site(self.fargo_site)
66
        response = requests.get(path,
70
        try:
71
            response = requests.get(
72
                path,
67 73
                remote_service=get_fargo_site(self.fargo_site),
68 74
                user=self.get_concerned_user(context),
69 75
                raise_if_not_cached=not(context.get('synchronous')),
76
                log_errors=False,
70 77
                headers={'accept': 'application/json'})
71
        if response.status_code == 200:
78
            response.raise_for_status()
79
        except requests.RequestException as e:
80
            if not e.response or e.response.status_code != 403:
81
                logger.error('failed to get %s on %s: %s', path, self.fargo_site, e,
82
                             extra={'request': context.get('request')})
83
            return {}
84
        else:
72 85
            return response.json()
73
        return {}
74 86

  
75 87
    def render(self, context):
76 88
        context.update(self.get_json('api/documents/recently-added/', context))
77
-