20 #include <ubuntu/download_manager/metatypes.h>
24 const QString DBUS_ERROR_STRING =
"DBusError: %1 - %2";
25 const QString AUTH_ERROR_STRING =
"AuthError: %1 - %2";
26 const QString HTTP_ERROR_STRING =
"HttpError: %1 - %2";
27 const QString NETWORK_ERROR_STRING =
"NetworkError: %1 - %2";
28 const QString PROCESS_ERROR_STRING =
"ProcessError: %1 - %2\nExit code: %3\nStdout: %4\nStderr:%5";
29 const QString HASH_ERROR_STRING =
"Hash validation error using %1: Expected result is %2 but result was %3.";
34 namespace DownloadManager {
41 Q_DECLARE_PUBLIC(Error)
44 ErrorPrivate(Error::Type type, Error* parent)
53 QString errorString()
const {
60 return "NetworkError";
62 return "ProcessError";
75 class DBusErrorPrivate {
76 Q_DECLARE_PUBLIC(DBusError)
79 DBusErrorPrivate(QDBusError err, DBusError* parent)
84 inline QString message()
const {
85 return _err.message();
88 inline QString name()
const {
92 inline QString errorString()
const {
93 return DBUS_ERROR_STRING.arg(_err.name(), _err.message());
101 class AuthErrorPrivate {
102 Q_DECLARE_PUBLIC(AuthError)
105 AuthErrorPrivate(Transfers::Errors::AuthErrorStruct err, AuthError* parent)
111 switch(_err.getType()) {
112 case Transfers::Errors::AuthErrorStruct::Proxy:
119 inline QString getTypeString()
const {
120 switch(_err.getType()) {
121 case Transfers::Errors::AuthErrorStruct::Proxy:
128 inline QString phrase()
const {
129 return _err.getPhrase();
132 inline QString errorString()
const {
133 return AUTH_ERROR_STRING.arg(getTypeString(), _err.getPhrase());
137 Transfers::Errors::AuthErrorStruct _err;
141 class HttpErrorPrivate {
142 Q_DECLARE_PUBLIC(HttpError)
145 HttpErrorPrivate(Transfers::Errors::HttpErrorStruct err, HttpError* parent)
150 inline int code()
const {
151 return _err.getCode();
154 inline QString phrase()
const {
155 return _err.getPhrase();
158 inline QString errorString()
const {
159 return HTTP_ERROR_STRING.arg(QString::number(_err.getCode()),
164 Transfers::Errors::HttpErrorStruct _err;
168 class NetworkErrorPrivate {
169 Q_DECLARE_PUBLIC(NetworkError)
172 NetworkErrorPrivate(Transfers::Errors::NetworkErrorStruct err,
173 NetworkError* parent)
183 inline QString phrase()
const {
184 return _err.getPhrase();
187 inline QString errorString()
const {
188 return NETWORK_ERROR_STRING.arg(QString::number(_err.getCode()),
193 Transfers::Errors::NetworkErrorStruct _err;
197 class ProcessErrorPrivate {
198 Q_DECLARE_PUBLIC(ProcessError)
201 ProcessErrorPrivate(Transfers::Errors::ProcessErrorStruct err,
202 ProcessError* parent)
207 QProcess::ProcessError code()
const {
208 auto code =
static_cast<QProcess::ProcessError
>(_err.getCode());
212 QString phrase()
const {
213 return _err.getPhrase();
216 inline int exitCode()
const {
217 return _err.getExitCode();
220 inline QString standardOut()
const {
221 return _err.getStandardOutput();
224 inline QString standardError()
const {
225 return _err.getStandardError();
228 inline QString errorString()
const {
229 return PROCESS_ERROR_STRING.arg(QString::number(_err.getCode()),
230 _err.getPhrase(), QString::number(_err.getExitCode()),
231 _err.getStandardOutput(), _err.getStandardError());
235 Transfers::Errors::ProcessErrorStruct _err;
239 class HashErrorPrivate {
240 Q_DECLARE_PUBLIC(HashError)
243 HashErrorPrivate (Transfers::Errors::HashErrorStruct err, HashError* parent)
248 inline QString method()
const {
249 return _err.getMethod();
252 inline QString expected()
const {
253 return _err.getExpected();
256 inline QString checksum()
const {
257 return _err.getChecksum();
260 inline QString errorString()
const {
261 return HASH_ERROR_STRING.arg(_err.getMethod()).arg(_err.getExpected()).arg(_err.getChecksum());
265 Transfers::Errors::HashErrorStruct _err;
275 d_ptr(new ErrorPrivate(type, this)) {
291 return d->errorString();
296 d_ptr(new DBusErrorPrivate(err, this)) {
299 DBusError::~DBusError() {
304 DBusError::message() {
316 DBusError::errorString() {
318 return d->errorString();
323 d_ptr(new AuthErrorPrivate(err, this)) {
345 return d->errorString();
350 d_ptr(new HttpErrorPrivate(err, this)) {
372 return d->errorString();
378 d_ptr(new NetworkErrorPrivate(err, this)) {
400 return d->errorString();
406 d_ptr(new ProcessErrorPrivate(err, this)) {
419 QProcess::ProcessError
428 return d->exitCode();
434 return d->standardOut();
440 return d->standardError();
446 return d->errorString();
451 d_ptr(new HashErrorPrivate(errStruct, this)) {
467 return d->expected();
473 return d->checksum();
479 return d->errorString();
The Error class is the base class that represents an error in the download manager API...
QString errorString() override
QString errorString() override
QString errorString() override
QProcess::ProcessError code()
ProcessError(Transfers::Errors::ProcessErrorStruct err, QObject *parent)
NetworkError(Transfers::Errors::NetworkErrorStruct err, QObject *parent)
The HashError represents an error that occurred during the hash validation after the download...
HashError(Transfers::Errors::HashErrorStruct err, QObject *parent)
DBusError(QDBusError err, QObject *parent=0)
HttpError(Transfers::Errors::HttpErrorStruct err, QObject *parent)
AuthError(Transfers::Errors::AuthErrorStruct err, QObject *parent)
Error(Type type, QObject *parent=0)
The NetworkError represents an error that occurred during the download request.
virtual QString errorString()
The HttpError represents an error that occurred during the download request.
QString errorString() override
The ProcessError represents an error that occurred during the post processing of a downloaded file...
QString errorString() override
The AuthError represents an authentication error that occurred during the request of the download...