KDAV

daverror.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Sandro KnauƟ <sknauss@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "daverror.h"
8#include <KLocalizedString>
9
10#include <KIO/Global>
11#include <KIO/Job>
12
13using namespace KDAV;
14
15namespace KDAV
16{
17class ErrorPrivate : public QSharedData
18{
19public:
20 ErrorNumber mErrorNumber = NO_ERR;
21 int mResponseCode = 0;
22 int mJobErrorCode = 0;
23 QString mErrorText;
24};
25}
26
27Error::Error()
28 : d(new ErrorPrivate)
29{
30}
31
32Error::Error(ErrorNumber errNo, int responseCode, const QString &errorText, int jobErrorCode)
33 : d(new ErrorPrivate)
34{
35 d->mErrorNumber = errNo;
36 d->mResponseCode = responseCode;
37 d->mErrorText = errorText;
38 d->mJobErrorCode = jobErrorCode;
39}
40
41Error::Error(const Error &) = default;
42Error::Error(Error &&) = default;
43Error::~Error() = default;
44Error &Error::operator=(const Error &) = default;
45Error &Error::operator=(Error &&) = default;
46
47ErrorNumber Error::errorNumber() const
48{
49 return d->mErrorNumber;
50}
51
52QString Error::internalErrorText() const
53{
54 return d->mErrorText;
55}
56
57int Error::jobErrorCode() const
58{
59 return d->mJobErrorCode;
60}
61
62int Error::responseCode() const
63{
64 return d->mResponseCode;
65}
66
67QString KDAV::Error::translatedJobError() const
68{
69 QString err;
70 if (d->mJobErrorCode > 0 && d->mJobErrorCode != KIO::ERR_WORKER_DEFINED) {
71 err = KIO::buildErrorString(d->mJobErrorCode, d->mErrorText);
72 } else {
73 err = d->mErrorText;
74 }
75 return err;
76}
77
78QString Error::errorText() const
79{
80 QString result;
81
82 QString err = translatedJobError();
83
84 switch (d->mErrorNumber) {
85 case ERR_PROBLEM_WITH_REQUEST:
86 // User-side error
87 if (d->mResponseCode == 401) {
88 err = i18n("Invalid username/password");
89 } else if (d->mResponseCode == 403) {
90 err = i18n("Access forbidden");
91 } else if (d->mResponseCode == 404) {
92 err = i18n("Resource not found");
93 } else {
94 err = i18n("HTTP error");
95 }
96 result = i18n("There was a problem with the request.\n%1 (%2).", err, d->mResponseCode);
97 break;
98 case ERR_NO_MULTIGET:
99 result = i18n("Protocol for the collection does not support MULTIGET");
100 break;
101 case ERR_SERVER_UNRECOVERABLE:
102 result = i18n("The server encountered an error that prevented it from completing your request: %1 (%2)", err, d->mResponseCode);
103 break;
104 case ERR_COLLECTIONDELETE:
105 result = i18n("There was a problem with the request. The collection has not been deleted from the server.\n%1 (%2).", err, d->mResponseCode);
106 break;
107 case ERR_COLLECTIONFETCH:
108 result = i18n("Invalid responses from backend");
109 break;
110 case ERR_COLLECTIONFETCH_XQUERY_SETFOCUS:
111 result = i18n("Error setting focus for XQuery");
112 break;
113 case ERR_COLLECTIONFETCH_XQUERY_INVALID:
114 result = i18n("Invalid XQuery submitted by DAV implementation");
115 break;
116 case ERR_COLLECTIONMODIFY:
117 result = i18n(
118 "There was a problem with the request. The collection has not been modified on the server.\n"
119 "%1 (%2).",
120 err,
121 d->mResponseCode);
122 break;
123 case ERR_COLLECTIONMODIFY_NO_PROPERITES:
124 result = i18n("No properties to change or remove");
125 break;
126 case ERR_COLLECTIONMODIFY_RESPONSE:
127 result = i18n("There was an error when modifying the properties");
128 if (!d->mErrorText.isEmpty()) {
129 result.append(i18n("\nThe server returned more information:\n%1", d->mErrorText));
130 }
131 break;
132 case ERR_ITEMCREATE:
133 result = i18n("There was a problem with the request. The item has not been created on the server.\n%1 (%2).", err, d->mResponseCode);
134 break;
135 case ERR_ITEMDELETE:
136 result = i18n("There was a problem with the request. The item has not been deleted from the server.\n%1 (%2).", err, d->mResponseCode);
137 break;
138 case ERR_ITEMMODIFY:
139 result = i18n("There was a problem with the request. The item was not modified on the server.\n%1 (%2).", err, d->mResponseCode);
140 break;
141 case ERR_ITEMLIST: {
142 result = i18n("There was a problem with the request.");
143 break;
144 };
145 case ERR_ITEMLIST_NOMIMETYPE:
146 result = i18n("There was a problem with the request. The requested MIME types are not supported.");
147 break;
148 case NO_ERR:
149 break;
150 }
151 return result;
152}
DAV operation error.
Definition daverror.h:47
QString i18n(const char *text, const TYPE &arg...)
The KDAV namespace.
ErrorNumber
DAV operation error codes.
Definition daverror.h:20
KIOCORE_EXPORT QString buildErrorString(int errorCode, const QString &errorText)
ERR_WORKER_DEFINED
QString & append(QChar ch)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:16:34 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.