From 4ac9ad1407b0273c4c1e0ca78069f25db3700163 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 29 Jan 2021 14:37:29 +1000 Subject: [PATCH] show actual error when graphData fails The original reason for the catch-all message was users with bad data such as decimal intervals, but those get automatically coerced these days. The common case should now be invalid search strings, which we can show verbatim. --- ftl/core/statistics.ftl | 1 - qt/aqt/mediasrv.py | 13 ++++++++----- ts/graphs/GraphsPage.svelte | 2 +- ts/lib/postrequest.ts | 3 ++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/ftl/core/statistics.ftl b/ftl/core/statistics.ftl index 0b5fc5eb5..8b122a644 100644 --- a/ftl/core/statistics.ftl +++ b/ftl/core/statistics.ftl @@ -172,7 +172,6 @@ statistics-elapsed-time-years = { $amount }y ## -statistics-error-fetching = Error searching - please check your search is correct, or use the Check Database feature. statistics-average-for-days-studied = Average for days studied statistics-total = Total statistics-days-studied = Days studied diff --git a/qt/aqt/mediasrv.py b/qt/aqt/mediasrv.py index 5482b849f..b37282afc 100644 --- a/qt/aqt/mediasrv.py +++ b/qt/aqt/mediasrv.py @@ -287,11 +287,14 @@ def handle_post(path: str) -> Response: return flask.make_response("Collection not open", HTTPStatus.NOT_FOUND) if path in post_handlers: - if data := post_handlers[path](): - response = flask.make_response(data) - response.headers["Content-Type"] = "application/binary" - else: - response = flask.make_response("", HTTPStatus.NO_CONTENT) + try: + if data := post_handlers[path](): + response = flask.make_response(data) + response.headers["Content-Type"] = "application/binary" + else: + response = flask.make_response("", HTTPStatus.NO_CONTENT) + except Exception as e: + return flask.make_response(str(e), HTTPStatus.INTERNAL_SERVER_ERROR) else: response = flask.make_response( f"Unhandled post to {path}", diff --git a/ts/graphs/GraphsPage.svelte b/ts/graphs/GraphsPage.svelte index 2597a09f0..05ade8f0b 100644 --- a/ts/graphs/GraphsPage.svelte +++ b/ts/graphs/GraphsPage.svelte @@ -37,7 +37,7 @@ revlogRange = daysToRevlogRange(days); } catch (e) { sourceData = null; - alert(i18n.tr(i18n.TR.STATISTICS_ERROR_FETCHING)); + alert(e); } active = false; }; diff --git a/ts/lib/postrequest.ts b/ts/lib/postrequest.ts index 100fe668f..a3075361b 100644 --- a/ts/lib/postrequest.ts +++ b/ts/lib/postrequest.ts @@ -7,7 +7,8 @@ export async function postRequest(path: string, body: string): Promise