fix: Avoid 500 when sanejs is unreachable

pull/92/head
Raphaël Vinot 2020-09-25 12:02:40 +02:00
parent 8c97701ed7
commit 3ce4f85118
1 changed files with 10 additions and 4 deletions

View File

@ -168,6 +168,8 @@ class Indexing():
class Context():
def __init__(self, sanejs: Optional[SaneJavaScript] = None):
self.logger = logging.getLogger(f'{self.__class__.__name__}')
self.logger.setLevel(get_config('generic', 'loglevel'))
self.redis: Redis = Redis(unix_socket_path=get_socket_path('indexing'), db=1, decode_responses=True)
self.sanejs = sanejs
self._cache_known_content()
@ -267,10 +269,14 @@ class Context():
if to_lookup and self.sanejs and self.sanejs.available:
# Query sanejs on the remaining ones
for h, entry in self.sanejs.hashes_lookup(to_lookup).items():
libname, version, path = entry[0].split("|")
known_content_table[h] = {'type': 'sanejs',
'details': (libname, version, path, len(entry))}
try:
for h, entry in self.sanejs.hashes_lookup(to_lookup).items():
libname, version, path = entry[0].split("|")
known_content_table[h] = {'type': 'sanejs',
'details': (libname, version, path, len(entry))}
except json.decoder.JSONDecodeError as e:
self.logger.warning(f'Something went wring with sanejs: {e}')
return known_content_table
def store_known_legitimate_tree(self, tree: CrawledTree):