Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make DB timeout message more explicit #284

Merged
merged 15 commits into from
Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/assets/locales/en/tdp.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"savedNotification": "{{type}} \"{{name}}\" successfully saved",
"deletedNotification": "{{type}} \"{{name}}\" successfully deleted",
"requestedUrl": "The requested URL was:",
"errorNotification": "<strong>Error {{status}} ({{statusText}})</strong>: {{body}}",
"errorNotification": "<strong>Error {{status}} ({{statusText}})</strong>: {{- body}}",

"ViewWrapper": {
"showHelp": "Show Help",
Expand Down
5 changes: 5 additions & 0 deletions src/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ let errorAlertHandler = (error: any) => {
if (error instanceof Response || error.response instanceof Response) {
const xhr: Response = error instanceof Response ? error : error.response;
return xhr.text().then((body: string) => {
if (xhr.status === 408) {
body = `Your data request could not be completed. Therefore, it was cancelled.
This problem might have been caused by requesting too much data at once.
In case of any questions, please contact the administrator.`;
}
if (xhr.status !== 400) {
body = `${body}<hr>
${i18n.t('tdp:core.requestedUrl')}<br><a href="${xhr.url}" target="_blank" rel="noopener" class="alert-link">${(xhr.url.length > 100) ? xhr.url.substring(0, 100) + '...' : xhr.url}</a>`;
Expand Down
10 changes: 6 additions & 4 deletions tdp_core/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,13 @@ def execute(self, sql, **kwargs):
:param kwargs: additional args to replace
:return: the session result
"""
import sqlalchemy
parsed = to_query(sql, self._supports_array_parameter, kwargs)
_log.info('%s (%s)', parsed, kwargs)
return self._session.execute(parsed, kwargs)
try:
return self._session.execute(parsed, kwargs)
except sqlalchemy.exc.OperationalError as error:
abort(408, error)

def run(self, sql, **kwargs):
"""
Expand All @@ -137,9 +141,7 @@ def run(self, sql, **kwargs):
:param kwargs: args for this query
:return: list of dicts
"""
parsed = to_query(sql, self._supports_array_parameter, kwargs)
_log.info('%s (%s)', parsed, kwargs)
thinkh marked this conversation as resolved.
Show resolved Hide resolved
result = self._session.execute(parsed, kwargs)
result = self.execute(sql, **kwargs)
columns = result.keys()
return [{c: r[c] for c in columns} for r in result]

Expand Down