Merge lp:~mikemc/ubuntuone-credentials/report-more-errors into lp:ubuntuone-credentials

Proposed by Mike McCracken
Status: Merged
Approved by: dobey
Approved revision: 45
Merged at revision: 34
Proposed branch: lp:~mikemc/ubuntuone-credentials/report-more-errors
Merge into: lp:ubuntuone-credentials
Prerequisite: lp:~mikemc/ubuntuone-credentials/add-2fa
Diff against target: 105 lines (+20/-12)
3 files modified
libubuntuoneauth/network.cpp (+17/-9)
libubuntuoneauth/ssoservice.cpp (+2/-2)
libubuntuoneauth/ssoservice.h (+1/-1)
To merge this branch: bzr merge lp:~mikemc/ubuntuone-credentials/report-more-errors
Reviewer Review Type Date Requested Status
dobey (community) Approve
Diego Sarmentero (community) Approve
Review via email: mp+173230@code.launchpad.net

Commit message

Add error signal for failure cases in Network class - covers connection failures.

Description of the change

Add error signal for failure cases in Network class - covers connection failures.

To test, turn off networking and try logging in via the music login app.
Without this branch, it will spin forever, because the network code never signals the upper layers that it has gotten an error and is giving up.

With the branch you should get a generic 'try again later' error message.

To post a comment you must log in.
Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

+1

review: Approve
Revision history for this message
dobey (dobey) wrote :

+ emit ErrorOccurred(ErrorResponse(0, QString(), LOGIN_FAILED, QString()));

Why are these empty QString() exactly? Wouldn't it be more appropriate to include the message we're shoving to qDebug() here, in ErrorResponse object (I think one of those QString() is supposed to be the actual error message), and have a single qDebug() inside the ErrorResponse ctor (or an extra method on it, which does the qDebug() which we just call after creating?

review: Needs Information
Revision history for this message
Mike McCracken (mikemc) wrote :

The QStrings are empty because nothing in the signal handler uses them. The ErrorResponse object looks like it was written assuming that you'd have an HTTP response to fit in there.
So, for errors that happen lower than HTTP, it's an awkward fit.

Improvement based on irc discussion will be to use the ErrorResponse message instead of qDebug()s at each new spot, since they get logged by the first signal handler in the chain

42. By Mike McCracken

merge add-2fa

43. By Mike McCracken

clean up use of ErrorResponse, add one more error signal to avoid ever returning without signaling.

44. By Mike McCracken

merge with add-2fa

45. By Mike McCracken

merge with add-2fa

Revision history for this message
dobey (dobey) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libubuntuoneauth/network.cpp'
2--- libubuntuoneauth/network.cpp 2013-06-14 22:39:59 +0000
3+++ libubuntuoneauth/network.cpp 2013-07-11 23:11:26 +0000
4@@ -23,10 +23,12 @@
5
6 #include <QStringList>
7
8+#include "errormessages.h"
9 #include "network.h"
10 #include "responses.h"
11 #include "requests.h"
12
13+#define NO_HTTP_REASON QString("No HTTP error reason")
14
15 namespace UbuntuOne {
16
17@@ -51,30 +53,35 @@
18 /* TODO: see if we really need to do this check, we could just operate
19 on a bad value as being an error rather than the extra check? */
20 if (!statusAttr.isValid()) {
21- qDebug() << "Invalid status received!";
22+ QString errmsg = QString("Invalid status attribute in Network::OnReply");
23+ // Use login failed code, which results in generic error message:
24+ emit ErrorOccurred(ErrorResponse(0, NO_HTTP_REASON, LOGIN_FAILED, errmsg));
25 return;
26 }
27
28 int httpStatus = statusAttr.toInt();
29
30- qDebug() << "Network::OnReply from " << reply->url();
31- qDebug() << "Network::OnReply status: " << httpStatus;
32+ qDebug() << "Network::OnReply from " << reply->url()
33+ << " status: " << httpStatus;
34
35 QByteArray payload = reply->readAll();
36 if (payload.isEmpty()) {
37- qDebug() << "empty payload";
38- return; /* TODO: Do something to signal we're having a bad time. */
39+ QString errmsg = QString("Network::OnReply: empty payload, giving up.");
40+ emit ErrorOccurred(ErrorResponse(0, NO_HTTP_REASON, LOGIN_FAILED, errmsg));
41+ return;
42 }
43
44 QJsonDocument document = QJsonDocument::fromJson(payload);
45- /* TODO: add logging or raise some type of error signal? */
46+
47 if (document.isEmpty()) {
48- qDebug() << "oops, received empty document";
49+ QString errmsg = QString("Network::OnReply received empty document");
50+ emit ErrorOccurred(ErrorResponse(0, NO_HTTP_REASON, LOGIN_FAILED, errmsg));
51 return;
52 }
53
54 if (!document.isObject()) {
55- qDebug() << "uh oh, this isn't good.";
56+ QString errmsg = QString("Network::OnReply received invalid QJsonDocument");
57+ emit ErrorOccurred(ErrorResponse(0, NO_HTTP_REASON, LOGIN_FAILED, errmsg));
58 return;
59 }
60
61@@ -92,7 +99,8 @@
62 QVariant phraseAttr = reply->attribute(
63 QNetworkRequest::HttpReasonPhraseAttribute);
64 if (!phraseAttr.isValid()) {
65- qDebug() << "got a bad HTTP reason";
66+ QString errmsg = QString("HTTP reason phrase is invalid");
67+ emit ErrorOccurred(ErrorResponse(httpStatus, NO_HTTP_REASON, LOGIN_FAILED, errmsg));
68 return;
69 }
70 QString httpReason = phraseAttr.toString();
71
72=== modified file 'libubuntuoneauth/ssoservice.cpp'
73--- libubuntuoneauth/ssoservice.cpp 2013-07-11 23:11:26 +0000
74+++ libubuntuoneauth/ssoservice.cpp 2013-07-11 23:11:26 +0000
75@@ -71,7 +71,7 @@
76 this, SLOT(handleTwoFactorAuthRequired()));
77 connect(&(_provider),
78 SIGNAL(ErrorOccurred(const ErrorResponse&)),
79- this, SLOT(errorOcurred(const ErrorResponse&)));
80+ this, SLOT(errorOccurred(const ErrorResponse&)));
81 }
82
83 void SSOService::getCredentials()
84@@ -197,7 +197,7 @@
85 _keyring->deleteToken();
86 }
87
88- void SSOService::errorOcurred(const ErrorResponse& error)
89+ void SSOService::errorOccurred(const ErrorResponse& error)
90 {
91 _tempPassword = "";
92 emit requestFailed(error);
93
94=== modified file 'libubuntuoneauth/ssoservice.h'
95--- libubuntuoneauth/ssoservice.h 2013-07-11 23:11:26 +0000
96+++ libubuntuoneauth/ssoservice.h 2013-07-11 23:11:26 +0000
97@@ -63,7 +63,7 @@
98 void handleCredentialsNotFound();
99 void tokenReceived(const OAuthTokenResponse& token);
100 void accountRegistered(const AccountResponse& account);
101- void errorOcurred(const ErrorResponse&);
102+ void errorOccurred(const ErrorResponse&);
103 void handleTwoFactorAuthRequired();
104
105 private:

Subscribers

People subscribed via source and target branches

to all changes: