Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #76 from plavacquery/QMAPS-968
Browse files Browse the repository at this point in the history
catch when http and json extract fail
  • Loading branch information
amatissart authored Jul 22, 2019
2 parents 898e8c1 + 534ba0b commit bb10d50
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions idunn/api/kuzzle.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import requests
from idunn import settings
import logging
from apistar.exceptions import HTTPException

from idunn import settings
logger = logging.getLogger(__name__)

class KuzzleClient:
def __init__(self):
Expand Down Expand Up @@ -28,8 +31,8 @@ def fetch_event_places(self, bbox, size) -> list:
'geo_bounding_box': {
'geo_loc': {
'top_left': {
'lat': top,
'lon': left
'lat': top,
'lon': left
},
'bottom_right': {
'lat': bot,
Expand All @@ -51,7 +54,14 @@ def fetch_event_places(self, bbox, size) -> list:
'size': size
}
bbox_places = self.session.post(url_kuzzle, json=query)
bbox_places = bbox_places.json()
bbox_places.raise_for_status()
try:
bbox_places = bbox_places.json()
except Exception:
logger.error(f'Error with kuzzle JSON with request to {url_kuzzle} '
f'Got {bbox_places.content}', exc_info=True)
raise HTTPException(status_code=503)

bbox_places = bbox_places.get('result', {}).get('hits', [])
return bbox_places

Expand Down

0 comments on commit bb10d50

Please sign in to comment.