diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-01-29 14:03:29 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-01-29 14:03:29 +0100 |
commit | f675a280ad48a9a2ba7b38f81cf0dfdafb3a96b5 (patch) | |
tree | 85294428d345ab3ada99c65fd8a6fc128f83cb1f | |
parent | c9f928ea2ea10220d40cddf9d7fc8009a22cf02a (diff) | |
download | sink-f675a280ad48a9a2ba7b38f81cf0dfdafb3a96b5.tar.gz sink-f675a280ad48a9a2ba7b38f81cf0dfdafb3a96b5.zip |
Translate dav errors
-rw-r--r-- | examples/davresource/davresource.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
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 @@ | |||
31 | 31 | ||
32 | #include "contactpreprocessor.h" | 32 | #include "contactpreprocessor.h" |
33 | 33 | ||
34 | #include <QNetworkReply> | ||
34 | #include <KDAV2/DavCollection> | 35 | #include <KDAV2/DavCollection> |
35 | #include <KDAV2/DavCollectionsFetchJob> | 36 | #include <KDAV2/DavCollectionsFetchJob> |
36 | #include <KDAV2/DavItem> | 37 | #include <KDAV2/DavItem> |
37 | #include <KDAV2/DavItemsListJob> | 38 | #include <KDAV2/DavItemsListJob> |
38 | #include <KDAV2/DavItemFetchJob> | 39 | #include <KDAV2/DavItemFetchJob> |
39 | #include <KDAV2/EtagCache> | 40 | #include <KDAV2/EtagCache> |
41 | #include <KDAV2/DavJobBase> | ||
40 | 42 | ||
41 | //This is the resources entity type, and not the domain type | 43 | //This is the resources entity type, and not the domain type |
42 | #define ENTITY_TYPE_CONTACT "contact" | 44 | #define ENTITY_TYPE_CONTACT "contact" |
@@ -44,14 +46,29 @@ | |||
44 | 46 | ||
45 | using namespace Sink; | 47 | using namespace Sink; |
46 | 48 | ||
49 | static int translateDavError(KJob *job) | ||
50 | { | ||
51 | const int error = job->error(); | ||
52 | const int responseCode = static_cast<KDAV2::DavJobBase*>(job)->latestResponseCode(); | ||
53 | |||
54 | switch (responseCode) { | ||
55 | case QNetworkReply::HostNotFoundError: | ||
56 | return ApplicationDomain::NoServerError; | ||
57 | //Since we don't login we will just not have the necessary permissions ot view the object | ||
58 | case QNetworkReply::OperationCanceledError: | ||
59 | return ApplicationDomain::LoginError; | ||
60 | } | ||
61 | return ApplicationDomain::UnknownError; | ||
62 | } | ||
63 | |||
47 | static KAsync::Job<void> runJob(KJob *job) | 64 | static KAsync::Job<void> runJob(KJob *job) |
48 | { | 65 | { |
49 | return KAsync::start<void>([job](KAsync::Future<void> &future) { | 66 | return KAsync::start<void>([job](KAsync::Future<void> &future) { |
50 | QObject::connect(job, &KJob::result, [&future](KJob *job) { | 67 | QObject::connect(job, &KJob::result, [&future](KJob *job) { |
51 | SinkTrace() << "Job done: " << job->metaObject()->className(); | 68 | SinkTrace() << "Job done: " << job->metaObject()->className(); |
52 | if (job->error()) { | 69 | if (job->error()) { |
53 | SinkWarning() << "Job failed: " << job->errorString(); | 70 | SinkWarning() << "Job failed: " << job->errorString() << job->metaObject()->className() << job->error() << static_cast<KDAV2::DavJobBase*>(job)->latestResponseCode(); |
54 | future.setError(job->error(), job->errorString()); | 71 | future.setError(translateDavError(job), job->errorString()); |
55 | } else { | 72 | } else { |
56 | future.setFinished(); | 73 | future.setFinished(); |
57 | } | 74 | } |