fargo: hide user-not-found API errors and only that (#35352)
This commit is contained in:
parent
cd2fcfebab
commit
3baed95c28
|
@ -14,16 +14,22 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# 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/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.forms import models as model_forms
|
from django.forms import models as model_forms
|
||||||
from django.forms import Select
|
from django.forms import Select
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
from requests import RequestException, HTTPError
|
||||||
|
|
||||||
from combo.data.models import CellBase
|
from combo.data.models import CellBase
|
||||||
from combo.data.library import register_cell_class
|
from combo.data.library import register_cell_class
|
||||||
from combo.utils import requests
|
from combo.utils import requests
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@register_cell_class
|
@register_cell_class
|
||||||
class RecentDocumentsCell(CellBase):
|
class RecentDocumentsCell(CellBase):
|
||||||
|
@ -63,14 +69,31 @@ class RecentDocumentsCell(CellBase):
|
||||||
return hasattr(settings, 'KNOWN_SERVICES') and settings.KNOWN_SERVICES.get('fargo')
|
return hasattr(settings, 'KNOWN_SERVICES') and settings.KNOWN_SERVICES.get('fargo')
|
||||||
|
|
||||||
def get_json(self, path, context):
|
def get_json(self, path, context):
|
||||||
remote_service = get_fargo_site(self.fargo_site)
|
user = self.get_concerned_user(context)
|
||||||
response = requests.get(path,
|
try:
|
||||||
remote_service=get_fargo_site(self.fargo_site),
|
response = requests.get(path,
|
||||||
user=self.get_concerned_user(context),
|
remote_service=get_fargo_site(self.fargo_site),
|
||||||
raise_if_not_cached=not(context.get('synchronous')),
|
user=user,
|
||||||
headers={'accept': 'application/json'})
|
raise_if_not_cached=not(context.get('synchronous')),
|
||||||
if response.status_code == 200:
|
headers={'accept': 'application/json'},
|
||||||
|
log_errors=True)
|
||||||
|
response.raise_for_status()
|
||||||
return response.json()
|
return response.json()
|
||||||
|
except HTTPError as e:
|
||||||
|
status_code = e.response.status_code
|
||||||
|
try:
|
||||||
|
content = e.response.json()
|
||||||
|
except Exception:
|
||||||
|
err = None
|
||||||
|
else:
|
||||||
|
err = content.get('err') if isinstance(content, dict) else None
|
||||||
|
if status_code == 401 and err == 'user-not-found':
|
||||||
|
log = logger.info
|
||||||
|
else:
|
||||||
|
log = logger.error
|
||||||
|
log('could not retrieve recent documents for user %s: status-code=%s err=%s', user, status_code, err)
|
||||||
|
except RequestException as e:
|
||||||
|
logger.error('could not retrieve recent documents for user %s: %s', user, e)
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def render(self, context):
|
def render(self, context):
|
||||||
|
|
Loading…
Reference in New Issue