Ignore "Forbidden" errors shortly after Syncthing start
Not sure why I'm getting ``` Fehler beim Abfragen der Syncthing-Konfiguration: Error transferring http://127.0.0.1:8384/rest/system/config - server replied: Forbidden URL der Anfrage: http://127.0.0.1:8384/rest/system/config ``` one one of my setups but this kind of error can likely be ignored shortly after the start similar to other types of errors.
This commit is contained in:
parent
91ce946acb
commit
13730ab933
|
@ -552,7 +552,7 @@ void SyncthingApplet::handleDevicesChanged()
|
|||
void SyncthingApplet::handleInternalError(
|
||||
const QString &errorMsg, SyncthingErrorCategory category, int networkError, const QNetworkRequest &request, const QByteArray &response)
|
||||
{
|
||||
if (!InternalError::isRelevant(m_connection, category, networkError)) {
|
||||
if (!InternalError::isRelevant(m_connection, category, errorMsg, networkError)) {
|
||||
return;
|
||||
}
|
||||
auto error = InternalError(errorMsg, request.url(), response);
|
||||
|
|
|
@ -12,11 +12,58 @@ using namespace Data;
|
|||
|
||||
namespace QtGui {
|
||||
|
||||
/*!
|
||||
* \brief Returns whether to ignore inavailability after start or standby-wakeup.
|
||||
*/
|
||||
static bool ignoreInavailabilityAfterStart(
|
||||
const Settings::Settings &settings, const SyncthingLauncher *launcher, const SyncthingService *service, const QString &message, int networkError)
|
||||
{
|
||||
if (!settings.ignoreInavailabilityAfterStart) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// ignore only certain types of errors
|
||||
// note: Not sure how to check for "Forbidden" except for checking the error message.
|
||||
switch (networkError) {
|
||||
case QNetworkReply::ConnectionRefusedError:
|
||||
case QNetworkReply::HostNotFoundError:
|
||||
case QNetworkReply::TemporaryNetworkFailureError:
|
||||
case QNetworkReply::NetworkSessionFailedError:
|
||||
case QNetworkReply::ProxyConnectionRefusedError:
|
||||
case QNetworkReply::ProxyNotFoundError:
|
||||
break;
|
||||
default:
|
||||
if (message.contains(QLatin1String("Forbidden"))) {
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
// ignore inavailable shorty after the start
|
||||
if ((launcher && launcher->isRunning())
|
||||
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
||||
&& ((service && service->isSystemdAvailable()
|
||||
&& !service->isActiveWithoutSleepFor(launcher->activeSince(), settings.ignoreInavailabilityAfterStart))
|
||||
|| !launcher->isActiveFor(settings.ignoreInavailabilityAfterStart))
|
||||
#else
|
||||
&& !launcher->isActiveFor(settings.ignoreInavailabilityAfterStart)
|
||||
#endif
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
||||
if (service && !service->isActiveWithoutSleepFor(settings.ignoreInavailabilityAfterStart)) {
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns whether the error is relevant. Only in this case a notification for the error should be shown.
|
||||
* \todo Unify with SyncthingNotifier::isDisconnectRelevant().
|
||||
*/
|
||||
bool InternalError::isRelevant(const SyncthingConnection &connection, SyncthingErrorCategory category, int networkError)
|
||||
bool InternalError::isRelevant(const SyncthingConnection &connection, SyncthingErrorCategory category, const QString &message, int networkError)
|
||||
{
|
||||
// ignore overall connection errors when auto reconnect tries >= 1
|
||||
if (category != SyncthingErrorCategory::OverallConnection && category != SyncthingErrorCategory::TLS && connection.autoReconnectTries() >= 1) {
|
||||
|
@ -50,35 +97,6 @@ bool InternalError::isRelevant(const SyncthingConnection &connection, SyncthingE
|
|||
}
|
||||
#endif
|
||||
|
||||
// ignore inavailability after start or standby-wakeup
|
||||
if (settings.ignoreInavailabilityAfterStart) {
|
||||
switch (networkError) {
|
||||
case QNetworkReply::ConnectionRefusedError:
|
||||
case QNetworkReply::HostNotFoundError:
|
||||
case QNetworkReply::TemporaryNetworkFailureError:
|
||||
case QNetworkReply::NetworkSessionFailedError:
|
||||
case QNetworkReply::ProxyConnectionRefusedError:
|
||||
case QNetworkReply::ProxyNotFoundError:
|
||||
if ((launcher && launcher->isRunning())
|
||||
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
||||
&& ((service && service->isSystemdAvailable()
|
||||
&& !service->isActiveWithoutSleepFor(launcher->activeSince(), settings.ignoreInavailabilityAfterStart))
|
||||
|| !launcher->isActiveFor(settings.ignoreInavailabilityAfterStart))
|
||||
#else
|
||||
&& !launcher->isActiveFor(settings.ignoreInavailabilityAfterStart)
|
||||
#endif
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
||||
if (service && !service->isActiveWithoutSleepFor(settings.ignoreInavailabilityAfterStart)) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return !ignoreInavailabilityAfterStart(settings, launcher, service, message, networkError);
|
||||
}
|
||||
} // namespace QtGui
|
||||
|
|
|
@ -19,7 +19,8 @@ namespace QtGui {
|
|||
struct SYNCTHINGWIDGETS_EXPORT InternalError {
|
||||
explicit InternalError(const QString &message = QString(), const QUrl &url = QUrl(), const QByteArray &response = QByteArray());
|
||||
|
||||
static bool isRelevant(const Data::SyncthingConnection &connection, Data::SyncthingErrorCategory category, int networkError);
|
||||
static bool isRelevant(
|
||||
const Data::SyncthingConnection &connection, Data::SyncthingErrorCategory category, const QString &message, int networkError);
|
||||
|
||||
QString message;
|
||||
QUrl url;
|
||||
|
|
|
@ -199,7 +199,7 @@ void TrayIcon::handleErrorsCleared()
|
|||
void TrayIcon::showInternalError(
|
||||
const QString &errorMessage, SyncthingErrorCategory category, int networkError, const QNetworkRequest &request, const QByteArray &response)
|
||||
{
|
||||
if (!InternalError::isRelevant(trayMenu().widget().connection(), category, networkError)) {
|
||||
if (!InternalError::isRelevant(trayMenu().widget().connection(), category, errorMessage, networkError)) {
|
||||
return;
|
||||
}
|
||||
auto error = InternalError(errorMessage, request.url(), response);
|
||||
|
|
|
@ -396,7 +396,7 @@ void TrayWidget::showUsingPositioningSettings()
|
|||
void TrayWidget::showInternalError(
|
||||
const QString &errorMessage, SyncthingErrorCategory category, int networkError, const QNetworkRequest &request, const QByteArray &response)
|
||||
{
|
||||
if (!InternalError::isRelevant(connection(), category, networkError)) {
|
||||
if (!InternalError::isRelevant(connection(), category, errorMessage, networkError)) {
|
||||
return;
|
||||
}
|
||||
InternalErrorsDialog::addError(errorMessage, request.url(), response);
|
||||
|
|
Loading…
Reference in New Issue