Commit 7ce90beb authored by Shashwat Jolly's avatar Shashwat Jolly
Browse files

Handle more EteSync errors

parent 55293651
......@@ -50,14 +50,14 @@ void BaseHandler::setupItems(std::vector<EteSyncEntryPtr> &entries, Akonadi::Col
getItemListFromEntries(entries, changedItems, removedItems, collection, journalUid, prevUid);
collection.setRemoteRevision(prevUid);
new CollectionModifyJob(collection, this);
if (isIncremental) {
mResource->itemsRetrievedIncremental(changedItems, removedItems);
} else {
mResource->itemsRetrieved(changedItems);
}
collection.setRemoteRevision(prevUid);
new CollectionModifyJob(collection, this);
}
bool BaseHandler::createEteSyncEntry(const EteSyncSyncEntry *syncEntry, const EteSyncCryptoManager *cryptoManager, const Collection &collection)
......@@ -72,7 +72,7 @@ bool BaseHandler::createEteSyncEntry(const EteSyncSyncEntry *syncEntry, const Et
EteSyncEntry *entries[] = {entry.get(), NULL};
if (etesync_entry_manager_create(entryManager.get(), entries, collection.remoteRevision())) {
handleConflictError(collection);
mResource->handleTokenError();
mResource->handleError();
return false;
}
updateCollectionRevision(entry.get(), collection);
......@@ -139,9 +139,9 @@ bool BaseHandler::handleConflictError(const Collection &collection)
qCDebug(ETESYNC_LOG) << "Conflict error";
mResource->deferTask();
mResource->scheduleCustomTask(this, "syncCollection", QVariant::fromValue(collection), ResourceBase::Prepend);
return false;
return true;
}
return true;
return false;
}
void BaseHandler::taskDone()
......
......@@ -302,7 +302,7 @@ void CalendarTaskBaseHandler::collectionAdded(const Akonadi::Collection &collect
if (etesync_journal_manager_create(mClientState->journalManager(), journal.get())) {
qCDebug(ETESYNC_LOG) << "Could not create journal";
qCDebug(ETESYNC_LOG) << "EteSync error" << QStringFromCharPtr(CharPtr(etesync_get_error_message()));
mResource->handleTokenError();
mResource->handleError();
return;
}
......@@ -345,7 +345,7 @@ void CalendarTaskBaseHandler::collectionChanged(const Akonadi::Collection &colle
if (etesync_journal_manager_update(mClientState->journalManager(), journal.get())) {
qCDebug(ETESYNC_LOG) << "Could not update journal";
qCDebug(ETESYNC_LOG) << "EteSync error" << QStringFromCharPtr(CharPtr(etesync_get_error_message()));
mResource->handleTokenError();
mResource->handleError();
return;
}
......@@ -368,7 +368,7 @@ void CalendarTaskBaseHandler::collectionRemoved(const Akonadi::Collection &colle
if (etesync_journal_manager_delete(mClientState->journalManager(), journal.get())) {
qCDebug(ETESYNC_LOG) << "Could not delete journal";
qCDebug(ETESYNC_LOG) << "EteSync error" << QStringFromCharPtr(CharPtr(etesync_get_error_message()));
mResource->handleTokenError();
mResource->handleError();
return;
}
mResource->changeProcessed();
......
......@@ -307,7 +307,7 @@ void ContactHandler::collectionAdded(const Akonadi::Collection &collection, cons
if (etesync_journal_manager_create(mClientState->journalManager(), journal.get())) {
qCDebug(ETESYNC_LOG) << "Could not create journal";
qCDebug(ETESYNC_LOG) << "EteSync error" << QStringFromCharPtr(CharPtr(etesync_get_error_message()));
mResource->handleTokenError();
mResource->handleError();
return;
}
......@@ -342,7 +342,7 @@ void ContactHandler::collectionChanged(const Akonadi::Collection &collection)
if (etesync_journal_manager_update(mClientState->journalManager(), journal.get())) {
qCDebug(ETESYNC_LOG) << "Could not update journal";
qCDebug(ETESYNC_LOG) << "EteSync error" << QStringFromCharPtr(CharPtr(etesync_get_error_message()));
mResource->handleTokenError();
mResource->handleError();
return;
}
......@@ -365,7 +365,7 @@ void ContactHandler::collectionRemoved(const Akonadi::Collection &collection)
if (etesync_journal_manager_delete(mClientState->journalManager(), journal.get())) {
qCDebug(ETESYNC_LOG) << "Could not delete journal";
qCDebug(ETESYNC_LOG) << "EteSync error" << QStringFromCharPtr(CharPtr(etesync_get_error_message()));
mResource->handleTokenError();
mResource->handleError();
return;
}
mResource->changeProcessed();
......
......@@ -103,7 +103,7 @@ void EteSyncClientState::refreshUserInfo()
EteSyncUserInfoManagerPtr userInfoManager(etesync_user_info_manager_new(mClient.get()));
mUserInfo = etesync_user_info_manager_fetch(userInfoManager.get(), mUsername);
if (!mUserInfo) {
qCWarning(ETESYNC_LOG) << "initUserInfo() - User info obtained from server is NULL";
qCWarning(ETESYNC_LOG) << "refreshUserInfo() - User info obtained from server is NULL";
qCDebug(ETESYNC_LOG) << "EteSync error" << QStringFromCharPtr(CharPtr(etesync_get_error_message()));
return;
}
......
......@@ -152,7 +152,8 @@ void EteSyncResource::slotCollectionsRetrieved(KJob *job)
{
if (job->error()) {
qCWarning(ETESYNC_LOG) << "Error in fetching journals";
handleTokenError();
qCWarning(ETESYNC_LOG) << "EteSync error" << etesync_get_error_message();
handleError();
return;
}
EteSyncJournal **journals = qobject_cast<JournalsFetchJob *>(job)->journals();
......@@ -172,16 +173,38 @@ void EteSyncResource::slotCollectionsRetrieved(KJob *job)
collectionsRetrievalDone();
}
bool EteSyncResource::handleTokenError()
/**
* Handles all EteSync errors (except CONFLICT).
* To be called immediatey after an EteSync operation.
* CONFLICT error has been handled seperately in BaseHandler.
*/
bool EteSyncResource::handleError()
{
if (etesync_get_error_code() == EteSyncErrorCode::ETESYNC_ERROR_CODE_UNAUTHORIZED) {
qCDebug(ETESYNC_LOG) << "Invalid token";
deferTask();
connect(mClientState.get(), &EteSyncClientState::tokenRefreshed, this, &EteSyncResource::taskDone);
scheduleCustomTask(mClientState.get(), "refreshToken", QVariant(), ResourceBase::Prepend);
return false;
switch (etesync_get_error_code()) {
case ETESYNC_ERROR_CODE_UNAUTHORIZED: {
qCDebug(ETESYNC_LOG) << "Invalid token";
qCDebug(ETESYNC_LOG) << "EteSync error" << etesync_get_error_message();
deferTask();
connect(mClientState.get(), &EteSyncClientState::tokenRefreshed, this, &EteSyncResource::taskDone);
scheduleCustomTask(mClientState.get(), "refreshToken", QVariant(), ResourceBase::Prepend);
return true;
}
case ETESYNC_ERROR_CODE_GENERIC:
case ETESYNC_ERROR_CODE_ENCODING:
case ETESYNC_ERROR_CODE_INTEGRITY:
case ETESYNC_ERROR_CODE_ENCRYPTION:
case ETESYNC_ERROR_CODE_ENCRYPTION_MAC:
case ETESYNC_ERROR_CODE_PERMISSION_DENIED:
case ETESYNC_ERROR_CODE_INVALID_DATA:
case ETESYNC_ERROR_CODE_CONNECTION:
case ETESYNC_ERROR_CODE_HTTP: {
qCDebug(ETESYNC_LOG) << "EteSync error" << etesync_get_error_message();
qCDebug(ETESYNC_LOG) << "Cancelling task";
cancelTask();
return true;
}
}
return true;
return false;
}
void EteSyncResource::setupCollection(Collection &collection, EteSyncJournal *journal)
......@@ -285,8 +308,9 @@ void EteSyncResource::retrieveItems(const Akonadi::Collection &collection)
void EteSyncResource::slotItemsRetrieved(KJob *job)
{
if (job->error()) {
qCDebug(ETESYNC_LOG) << "Error in fetching entries";
qCWarning(ETESYNC_LOG) << job->errorText();
handleTokenError();
handleError();
return;
}
......
......@@ -66,7 +66,7 @@ protected:
void initialiseDirectory(const QString &path) const;
QString baseDirectoryPath() const;
bool handleTokenError();
bool handleError();
const EteSyncJournalPtr &getJournal(const QString &journalUid)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment