From f675a280ad48a9a2ba7b38f81cf0dfdafb3a96b5 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 29 Jan 2018 14:03:29 +0100 Subject: Translate dav errors --- examples/davresource/davresource.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'examples/davresource/davresource.cpp') diff --git a/examples/davresource/davresource.cpp b/examples/davresource/davresource.cpp index fa5e612..c8fd097 100644 --- a/examples/davresource/davresource.cpp +++ b/examples/davresource/davresource.cpp @@ -31,12 +31,14 @@ #include "contactpreprocessor.h" +#include #include #include #include #include #include #include +#include //This is the resources entity type, and not the domain type #define ENTITY_TYPE_CONTACT "contact" @@ -44,14 +46,29 @@ using namespace Sink; +static int translateDavError(KJob *job) +{ + const int error = job->error(); + const int responseCode = static_cast(job)->latestResponseCode(); + + switch (responseCode) { + case QNetworkReply::HostNotFoundError: + return ApplicationDomain::NoServerError; + //Since we don't login we will just not have the necessary permissions ot view the object + case QNetworkReply::OperationCanceledError: + return ApplicationDomain::LoginError; + } + return ApplicationDomain::UnknownError; +} + static KAsync::Job runJob(KJob *job) { return KAsync::start([job](KAsync::Future &future) { QObject::connect(job, &KJob::result, [&future](KJob *job) { SinkTrace() << "Job done: " << job->metaObject()->className(); if (job->error()) { - SinkWarning() << "Job failed: " << job->errorString(); - future.setError(job->error(), job->errorString()); + SinkWarning() << "Job failed: " << job->errorString() << job->metaObject()->className() << job->error() << static_cast(job)->latestResponseCode(); + future.setError(translateDavError(job), job->errorString()); } else { future.setFinished(); } -- cgit v1.2.3