Skip to content

Commit

Permalink
Option to enable network log on network failure
Browse files Browse the repository at this point in the history
  • Loading branch information
martinburchell committed Mar 28, 2024
1 parent adab51b commit 0ae04b4
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 13 deletions.
3 changes: 3 additions & 0 deletions docs/source/changelog.rst
Expand Up @@ -3883,3 +3883,6 @@ Current C++/SQLite client, Python/SQLAlchemy server

- Additional optional LGPL licensing for some Qt height-for-width layout code
to make it suitable for inclusion in libraries elsewhere.

- Make it easier to turn on error logging in the event of a network operation failure.
https://github.com/ucam-department-of-psychiatry/camcops/issues/336
60 changes: 48 additions & 12 deletions tablet_qt/core/camcopsapp.cpp
Expand Up @@ -508,12 +508,8 @@ void CamcopsApp::patientRegistrationFailed(
break;
}

uifunc::alert(
QString("%1\n\n%2").arg(base_message, additional_message),
tr("Error")
);

recreateMainMenu();
maybeRetryNetworkOperation(base_message, additional_message,
NetworkOperation::RegisterPatient);
}


Expand Down Expand Up @@ -543,7 +539,8 @@ void CamcopsApp::updateTaskSchedulesFailed(
handleNetworkFailure(
error_code,
error_string,
tr("There was a problem updating your task schedules.")
tr("There was a problem updating your task schedules."),
NetworkOperation::UpdateTaskSchedules
);
}

Expand All @@ -569,7 +566,8 @@ void CamcopsApp::uploadFailed(const NetworkManager::ErrorCode error_code,
handleNetworkFailure(
error_code,
error_string,
tr("There was a problem sending your completed tasks to the server.")
tr("There was a problem sending your completed tasks to the server."),
NetworkOperation::Upload
);
}

Expand Down Expand Up @@ -623,7 +621,8 @@ void CamcopsApp::retryUpload()

void CamcopsApp::handleNetworkFailure(const NetworkManager::ErrorCode error_code,
const QString& error_string,
const QString& base_message)
const QString& base_message,
CamcopsApp::NetworkOperation operation)
{
QString additional_message = "";

Expand Down Expand Up @@ -651,14 +650,51 @@ void CamcopsApp::handleNetworkFailure(const NetworkManager::ErrorCode error_code
break;
}

uifunc::alert(
maybeRetryNetworkOperation(base_message, additional_message, operation);
}


void CamcopsApp::maybeRetryNetworkOperation(const QString base_message,
const QString additional_message,
CamcopsApp::NetworkOperation operation)
{
bool try_again_with_log = uifunc::confirm(
QString("%1\n\n%2").arg(base_message, additional_message),
tr("Error")
tr("Error"),
tr("Try again with error log"),
tr("Dismiss")
);

recreateMainMenu();
if (!try_again_with_log) {
recreateMainMenu();

return;
}

enableNetworkLogging();

switch (operation) {
case NetworkOperation::RegisterPatient:
registerPatientWithServer();
break;

case NetworkOperation::UpdateTaskSchedules:
// it doesn't matter if we pass alert_unfinished_tasks as True or False
// here. We wouldn't be here if there were unfinished tasks.
updateTaskSchedules();
break;

case NetworkOperation::Upload:
upload();
break;

default:
// Shouldn't get here
break;
}
}


TaskSchedulePtrList CamcopsApp::getTaskSchedules()
{
TaskSchedulePtrList task_schedules;
Expand Down
13 changes: 12 additions & 1 deletion tablet_qt/core/camcopsapp.h
Expand Up @@ -237,9 +237,20 @@ class CamcopsApp : public QApplication
// For single user mode, register patient if not already done so
void maybeRegisterPatient();

enum class NetworkOperation {
RegisterPatient,
UpdateTaskSchedules,
Upload
};

void handleNetworkFailure(const NetworkManager::ErrorCode error_code,
const QString& error_string,
const QString& base_message);
const QString& base_message,
CamcopsApp::NetworkOperation operation);

void maybeRetryNetworkOperation(const QString base_message,
const QString additional_message,
CamcopsApp::NetworkOperation operation);

bool userConfirmedRetryPassword() const;
bool userConfirmedDeleteDatabases() const;
Expand Down

0 comments on commit 0ae04b4

Please sign in to comment.