Libkdav2

daverror.cpp
1/*
2 Copyright (c) 2016 Sandro Knauß <sknauss@kde.org>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17*/
18
19#include "daverror.h"
20
21using namespace KDAV2;
22
23Error::Error()
24 : mErrorNumber(NO_ERR)
25 , mHttpStatusCode(0)
26 , mResponseCode(0)
27 , mJobErrorCode(0)
28{
29}
30
31Error::Error(ErrorNumber errNo, int httpStatusCode, int responseCode, const QString &errorText, int jobErrorCode)
32 : mErrorNumber(errNo)
33 , mHttpStatusCode(httpStatusCode)
34 , mResponseCode(responseCode)
35 , mErrorText(errorText)
36 , mJobErrorCode(jobErrorCode)
37{
38}
39
40ErrorNumber Error::errorNumber() const
41{
42 return mErrorNumber;
43}
44
45QString Error::errorText() const
46{
47 return mErrorText;
48}
49
50int Error::jobErrorCode() const
51{
52 return mJobErrorCode;
53}
54
55int Error::httpStatusCode() const
56{
57 return mHttpStatusCode;
58}
59
60int Error::responseCode() const
61{
62 return mResponseCode;
63}
64
65QString Error::description() const
66{
67 switch (mErrorNumber) {
68 case ERR_PROBLEM_WITH_REQUEST: {
69 // User-side error
70 QString err;
71 if (mHttpStatusCode == 401) {
72 err = QStringLiteral("Invalid username/password");
73 } else if (mHttpStatusCode == 403) {
74 err = QStringLiteral("Access forbidden");
75 } else if (mHttpStatusCode == 404) {
76 err = QStringLiteral("Resource not found");
77 } else {
78 err = QStringLiteral("HTTP error");
79 }
80 return QStringLiteral("There was a problem with the request.\n"
81 "%1 (%2).").arg(err).arg(mHttpStatusCode);
82 }
83 case ERR_NO_MULTIGET:
84 return QStringLiteral("Protocol for the collection does not support MULTIGET");
85 case ERR_SERVER_UNRECOVERABLE:
86 return QStringLiteral("The server encountered an error that prevented it from completing your request: %1 (%2)").arg(mErrorText).arg(mHttpStatusCode);
87 case ERR_COLLECTIONDELETE:
88 return QStringLiteral("There was a problem with the request. The collection has not been deleted from the server.\n"
89 "%1 (%2).").arg(mErrorText).arg(mHttpStatusCode);
90 case ERR_COLLECTIONFETCH:
91 return QStringLiteral("Invalid responses from backend");
92 case ERR_COLLECTIONFETCH_XQUERY_SETFOCUS:
93 return QStringLiteral("Error setting focus for XQuery");
94 case ERR_COLLECTIONFETCH_XQUERY_INVALID:
95 return QStringLiteral("Invalid XQuery submitted by DAV implementation");
96 case ERR_COLLECTIONMODIFY:
97 return QStringLiteral("There was a problem with the request. The collection has not been modified on the server.\n"
98 "%1 (%2).").arg(mErrorText).arg(mHttpStatusCode);
99 case ERR_COLLECTIONMODIFY_NO_PROPERITES:
100 return QStringLiteral("No properties to change or remove");
101 case ERR_COLLECTIONMODIFY_RESPONSE: {
102 auto result = QStringLiteral("There was an error when modifying the properties");
103 if (!mErrorText.isEmpty()) {
104 result.append(QStringLiteral("\nThe server returned more information:\n%1").arg(mErrorText));
105 }
106 return result;
107 }
108 case ERR_COLLECTIONCREATE:
109 return QStringLiteral("There was an error when creating the collection");
110 case ERR_ITEMCREATE:
111 return QStringLiteral("There was a problem with the request. The item has not been created on the server.\n"
112 "%1 (%2).").arg(mErrorText).arg(mHttpStatusCode);
113 case ERR_ITEMDELETE:
114 return QStringLiteral("There was a problem with the request. The item has not been deleted from the server.\n"
115 "%1 (%2).").arg(mErrorText).arg(mHttpStatusCode);
116 case ERR_ITEMMODIFY:
117 return QStringLiteral("There was a problem with the request. The item was not modified on the server.\n"
118 "%1 (%2).").arg(mErrorText).arg(mHttpStatusCode);
119 case ERR_ITEMLIST:
120 return QStringLiteral("There was a problem with the request.");
121 case ERR_ITEMLIST_NOMIMETYPE:
122 return QStringLiteral("There was a problem with the request. The requested mimetypes are not supported.");
123 case NO_ERR:
124 break;
125 }
126 return mErrorText;
127}
QString arg(Args &&... args) const const
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:05 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.