Merge lp:~alecu/unity-scope-click/uncaught-error into lp:unity-scope-click

Proposed by Alejandro J. Cura
Status: Merged
Approved by: dobey
Approved revision: 70
Merged at revision: 70
Proposed branch: lp:~alecu/unity-scope-click/uncaught-error
Merge into: lp:unity-scope-click
Diff against target: 108 lines (+33/-12)
2 files modified
src/click-scope.vala (+10/-3)
src/download-manager.vala (+23/-9)
To merge this branch: bzr merge lp:~alecu/unity-scope-click/uncaught-error
Reviewer Review Type Date Requested Status
dobey (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+189188@code.launchpad.net

Commit message

Catch more download errors, and ask for credentials on 401

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
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 'src/click-scope.vala'
2--- src/click-scope.vala 2013-10-03 17:28:40 +0000
3+++ src/click-scope.vala 2013-10-03 22:37:23 +0000
4@@ -187,7 +187,7 @@
5 } else if (action_id.has_prefix(ACTION_DOWNLOAD_FAILED)) {
6 // we don't have access to the error message in SearchMetadata, LP: #1233836
7 var errormsg = "please check ubuntu-download-manager.log";
8- throw new ClickScopeError.INSTALL_ERROR("Installation failed: %s".printf(errormsg));
9+ preview = build_error_preview ("Installation failed: %s".printf(errormsg));
10 } else if (action_id == ACTION_DOWNLOAD_COMPLETED) {
11 results_invalidated(Unity.SearchType.GLOBAL);
12 results_invalidated(Unity.SearchType.DEFAULT);
13@@ -220,7 +220,7 @@
14 if (scope_error is ClickScopeError.LOGIN_ERROR) {
15 preview = build_login_error_preview (scope_error.message);
16 } else {
17- throw scope_error;
18+ preview = build_error_preview (scope_error.message);
19 }
20 } catch (GLib.Error e) {
21 debug ("Error building preview: %s", e.message);
22@@ -265,6 +265,13 @@
23 var download_object_path = yield signed_download.start_download (download_url, app_id);
24 debug ("download started: %s", download_object_path);
25 return download_object_path;
26+ } catch (DownloadError download_error) {
27+ debug ("Got DownloadError: %s", download_error.message);
28+ if (download_error is DownloadError.INVALID_CREDENTIALS) {
29+ throw new ClickScopeError.LOGIN_ERROR (download_error.message);
30+ } else {
31+ throw new ClickScopeError.INSTALL_ERROR (download_error.message);
32+ }
33 } catch (CredentialsError cred_error) {
34 debug ("Got CredentialsError trying to fetch token.");
35 throw new ClickScopeError.LOGIN_ERROR (cred_error.message);
36@@ -381,7 +388,7 @@
37 GLib.Source.remove (app_search_id);
38 }
39 app_search_id = GLib.Timeout.add_seconds (10, () => {
40- find_available_apps (search_query);
41+ find_available_apps.begin (search_query);
42 return false;
43 });
44 }
45
46=== modified file 'src/download-manager.vala'
47--- src/download-manager.vala 2013-09-21 00:17:03 +0000
48+++ src/download-manager.vala 2013-10-03 22:37:23 +0000
49@@ -81,7 +81,8 @@
50 }
51
52 errordomain DownloadError {
53- DOWNLOAD_ERROR
54+ DOWNLOAD_ERROR,
55+ INVALID_CREDENTIALS
56 }
57
58 public string? get_download_progress (string app_id) {
59@@ -123,9 +124,10 @@
60 credentials[TOKEN], credentials[TOKEN_SECRET]);
61 }
62
63- async string fetch_click_token(string download_url) {
64+ async string fetch_click_token(string download_url) throws DownloadError {
65 string click_token = null;
66 const string HEAD = "HEAD";
67+ DownloadError error = null;
68
69 var message = new Soup.Message (HEAD, sign_url(HEAD, download_url));
70 http_session.queue_message (message, (session, message) => {
71@@ -133,19 +135,31 @@
72 if (message.status_code == Soup.KnownStatusCode.OK && click_token != null) {
73 debug ("Click token received");
74 } else {
75- if (message.status_code == Soup.KnownStatusCode.OK) {
76- debug ("No X-Click-Token header received from download url: %s", download_url);
77- click_token = "fake token";
78- } else {
79- debug ("Web request failed: HTTP %u %s - %s",
80+ switch (message.status_code) {
81+ case Soup.KnownStatusCode.OK:
82+ var msg = "No X-Click-Token header received. Url was: %s".printf(download_url);
83+ debug (msg);
84+ error = new DownloadError.DOWNLOAD_ERROR (msg);
85+ break;
86+ case Soup.KnownStatusCode.UNAUTHORIZED:
87+ var msg = "The Ubuntu One credentials are invalid, please log in again.";
88+ debug (msg);
89+ error = new DownloadError.INVALID_CREDENTIALS (msg);
90+ break;
91+ default:
92+ var msg = "Web request failed: HTTP %u %s - %s".printf(
93 message.status_code, message.reason_phrase, download_url);
94- click_token = "fake token";
95+ debug (msg);
96+ error = new DownloadError.DOWNLOAD_ERROR (message.reason_phrase);
97+ break;
98 }
99- //error = new PurchaseError.PURCHASE_ERROR (message.reason_phrase);
100 }
101 fetch_click_token.callback ();
102 });
103 yield;
104+ if (error != null) {
105+ throw error;
106+ }
107 return click_token;
108 }
109

Subscribers

People subscribed via source and target branches