Skip to content

Commit

Permalink
display error when ts is not accessible
Browse files Browse the repository at this point in the history
  • Loading branch information
xgaia committed Jan 6, 2020
1 parent 102019c commit 92d6a18
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
56 changes: 32 additions & 24 deletions askomics/libaskomics/SparqlQueryLauncher.py
@@ -1,4 +1,7 @@
import time
import urllib
import traceback
import sys

from SPARQLWrapper import JSON, SPARQLWrapper

Expand Down Expand Up @@ -275,30 +278,35 @@ def execute_query(self, query):
TYPE
result
"""
start_time = time.time()
self.endpoint.setQuery(query)

# Debug
if self.settings.getboolean('askomics', 'debug'):
self.log.debug("Launch query on {} ({})".format(self.triplestore, self.url_endpoint))
self.log.debug(query)

# Update
if self.endpoint.isSparqlUpdateRequest():
self.endpoint.setMethod('POST')
# Virtuoso hack
if self.triplestore == 'virtuoso':
self.endpoint.queryType = "SELECT"

results = self.endpoint.query()
self.query_time = time.time() - start_time
# Select
else:
self.endpoint.setReturnFormat(JSON)
results = self.endpoint.query().convert()
self.query_time = time.time() - start_time
# self.log.debug(results)
return results
try:
start_time = time.time()
self.endpoint.setQuery(query)

# Debug
if self.settings.getboolean('askomics', 'debug'):
self.log.debug("Launch query on {} ({})".format(self.triplestore, self.url_endpoint))
self.log.debug(query)

# Update
if self.endpoint.isSparqlUpdateRequest():
self.endpoint.setMethod('POST')
# Virtuoso hack
if self.triplestore == 'virtuoso':
self.endpoint.queryType = "SELECT"

results = self.endpoint.query()
self.query_time = time.time() - start_time
# Select
else:
self.endpoint.setReturnFormat(JSON)
results = self.endpoint.query().convert()
self.query_time = time.time() - start_time
# self.log.debug(results)
return results

except urllib.error.URLError:
traceback.print_exc(file=sys.stdout)
raise urllib.error.URLError("Triplestore is not accessible")

def parse_results_old(self, json_results):
"""Parse result of sparql query
Expand Down
1 change: 1 addition & 0 deletions askomics/react/src/routes/ask/ask.jsx
Expand Up @@ -18,6 +18,7 @@ export default class Ask extends Component {
error: false,
errorMessage: null,
startpoints: [],
endpoints: [],
selected: null,
startSession: false,
publicQueries: [],
Expand Down

0 comments on commit 92d6a18

Please sign in to comment.