From cd5ecf7b381ebc76196931e213c92664c3443be8 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 20 Mar 2017 09:24:06 +0100 Subject: Make error codes part of the applicationdomain interface --- common/domain/applicationdomaintype.h | 12 ++++++++++++ common/notification.h | 16 ---------------- common/synchronizer.cpp | 3 ++- examples/imapresource/imapresource.cpp | 4 ++-- examples/mailtransportresource/mailtransportresource.cpp | 4 ++-- 5 files changed, 18 insertions(+), 21 deletions(-) diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h index 8ff3e8b..ae8e6bc 100644 --- a/common/domain/applicationdomaintype.h +++ b/common/domain/applicationdomaintype.h @@ -92,6 +92,18 @@ namespace Sink { namespace ApplicationDomain { +enum ErrorCode { + NoError = 0, + UnknownError, + NoServerError, + LoginError, + TransmissionError, +}; + +enum SuccessCode { + TransmissionSuccess +}; + struct SINK_EXPORT Error { }; diff --git a/common/notification.h b/common/notification.h index 87c22db..4b52274 100644 --- a/common/notification.h +++ b/common/notification.h @@ -49,22 +49,6 @@ public: Success = 0, Failure }; - /** - * Used as code for Warning/Error type notifications - */ - enum ErrorCode { - NoError = 0, - UnknownError, - NoServerAvailable, - LoginFailed, - TransmissionFailed, - }; - /** - * Used as code for Info type notifications - */ - enum SuccessCode { - TransmissionSucceeded - }; QByteArray id; int type = 0; diff --git a/common/synchronizer.cpp b/common/synchronizer.cpp index ff13783..4ed6e3a 100644 --- a/common/synchronizer.cpp +++ b/common/synchronizer.cpp @@ -391,7 +391,7 @@ KAsync::Job Synchronizer::processSyncQueue() mSyncInProgress = true; }) .then(processRequest(request)) - .then([this](const KAsync::Error &error) { + .then([this, request](const KAsync::Error &error) { SinkTraceCtx(mLogCtx) << "Sync request processed"; mEntityStore->abortTransaction(); mSyncTransaction.abort(); @@ -403,6 +403,7 @@ KAsync::Job Synchronizer::processSyncQueue() } if (error) { SinkWarningCtx(mLogCtx) << "Error during sync: " << error; + emitNotification(Notification::Error, error.errorCode, error.errorMessage, request.requestId); } //In case we got more requests meanwhile. return processSyncQueue(); diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp index fff4dc7..b27c2b2 100644 --- a/examples/imapresource/imapresource.cpp +++ b/examples/imapresource/imapresource.cpp @@ -488,7 +488,7 @@ public: SinkWarning() << "Error during folder sync: " << error.errorMessage; } return imap->logout() - .then(KAsync::error(error)); + .then(KAsync::error(ApplicationDomain::LoginError, error.errorMessage)); }); } else if (query.type() == ApplicationDomain::getTypeName()) { //TODO @@ -560,7 +560,7 @@ public: SinkWarning() << "Error during sync: " << error.errorMessage; } return imap->logout() - .then(KAsync::error(error)); + .then(KAsync::error(ApplicationDomain::LoginError, error.errorMessage)); }); } return KAsync::error("Nothing to do"); diff --git a/examples/mailtransportresource/mailtransportresource.cpp b/examples/mailtransportresource/mailtransportresource.cpp index 72fe59d..6beb4e8 100644 --- a/examples/mailtransportresource/mailtransportresource.cpp +++ b/examples/mailtransportresource/mailtransportresource.cpp @@ -81,10 +81,10 @@ public: } if (!MailTransport::sendMessage(msg, settings.server.toUtf8(), settings.username.toUtf8(), settings.password.toUtf8(), settings.cacert.toUtf8(), options)) { SinkWarning() << "Failed to send message: " << mail; - emitNotification(Notification::Warning, Notification::TransmissionFailed, "Failed to send message."); + emitNotification(Notification::Warning, ApplicationDomain::TransmissionError, "Failed to send message."); return KAsync::error("Failed to send the message."); } else { - emitNotification(Notification::Info, Notification::TransmissionSucceeded, "Message successfully sent."); + emitNotification(Notification::Info, ApplicationDomain::TransmissionSuccess, "Message successfully sent."); } } syncStore().writeValue(mail.identifier(), "sent"); -- cgit v1.2.3