wcs: don't log errors if at least one wcs answers positively (#10672)
This commit is contained in:
parent
3b8d489824
commit
2a989d995a
|
@ -14,6 +14,8 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import logging
|
||||
|
||||
from django import template
|
||||
from django.db import models
|
||||
from django.forms import models as model_forms
|
||||
|
@ -141,6 +143,7 @@ class WcsBlurpMixin(object):
|
|||
wcs_sites = get_wcs_services()
|
||||
|
||||
wcs_sites = wcs_sites.copy()
|
||||
returns = set([])
|
||||
for wcs_slug, wcs_site in wcs_sites.items():
|
||||
url = wcs_site.get('url')
|
||||
if not url.endswith('/'):
|
||||
|
@ -152,10 +155,15 @@ class WcsBlurpMixin(object):
|
|||
remote_service=wcs_site,
|
||||
user=self.get_concerned_user(context),
|
||||
cache_duration=self.cache_duration,
|
||||
raise_if_not_cached=not(context.get('synchronous')))
|
||||
raise_if_not_cached=not(context.get('synchronous')),
|
||||
log_errors=False)
|
||||
returns.add(response.status_code)
|
||||
if response.status_code == 200:
|
||||
wcs_site['data'] = response.json()
|
||||
|
||||
if not 200 in returns: # not a single valid answer
|
||||
logging.error('failed to get data from any %s (%r)', self.api_url, returns)
|
||||
|
||||
return wcs_sites
|
||||
|
||||
def get_cell_extra_context(self, context):
|
||||
|
|
|
@ -43,6 +43,7 @@ class Requests(RequestsSession):
|
|||
without_user = kwargs.pop('without_user', False)
|
||||
federation_key = kwargs.pop('federation_key', 'auto') # 'auto', 'email', 'nameid'
|
||||
raise_if_not_cached = kwargs.pop('raise_if_not_cached', False)
|
||||
log_errors = kwargs.pop('log_errors', True)
|
||||
|
||||
if remote_service:
|
||||
if isinstance(user, dict):
|
||||
|
@ -95,7 +96,7 @@ class Requests(RequestsSession):
|
|||
url = sign_url(url, remote_service.get('secret'))
|
||||
|
||||
response = super(Requests, self).request(method, url, **kwargs)
|
||||
if response.status_code != 200:
|
||||
if response.status_code != 200 and log_errors:
|
||||
logging.error('failed to %s %s (%s)' % (method, url, response.status_code))
|
||||
if method == 'GET' and cache_duration and response.status_code == 200:
|
||||
cache.set(cache_key, response.content, cache_duration)
|
||||
|
|
Loading…
Reference in New Issue