Merge lp:~andrea.corbellini/beeseek/error-page into lp:beeseek/1.0

Proposed by Andrea Corbellini
Status: Merged
Merged at revision: not available
Proposed branch: lp:~andrea.corbellini/beeseek/error-page
Merge into: lp:beeseek/1.0
Diff against target: 340 lines
To merge this branch: bzr merge lp:~andrea.corbellini/beeseek/error-page
Reviewer Review Type Date Requested Status
Andrea Colangelo ui Approve
Jacopo Moretto (community) Approve
Review via email: mp+14786@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Andrea Corbellini (andrea.corbellini) wrote :

This branch adds a web page that is shown to the user when an error in the proxy occurs.

Currently it is only displayed when the host that the user is trying to connect to cannot be found, but in the future it will be used for any error.

How to test this change:

1. Start the server with 'beeseek-server start -t';
2. Start the peer with 'beeseek-peer start -t' and set it as your proxy;
3. Visit a URL that doesn't exist (e.g. <http://something/>)

You should see a page telling you that the host cannot be found.

Revision history for this message
Jacopo Moretto (jak-o) :
review: Approve
Revision history for this message
Jacopo Moretto (jak-o) :
review: Approve
Revision history for this message
Andrea Colangelo (warp10) :
review: Approve (ui)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'beeseek/app/log.py'
--- beeseek/app/log.py 2009-10-21 15:39:48 +0000
+++ beeseek/app/log.py 2009-11-12 13:55:22 +0000
@@ -141,7 +141,7 @@
141 for name in dir(self_obj):141 for name in dir(self_obj):
142 try:142 try:
143 value = getattr(self_obj, name)143 value = getattr(self_obj, name)
144 except StandardError:144 except Exception:
145 # XXX We can use somewhat better.145 # XXX We can use somewhat better.
146 value = NotImplementedError146 value = NotImplementedError
147 f_self[name] = value147 f_self[name] = value
148148
=== modified file 'beeseek/template/css.py'
--- beeseek/template/css.py 2009-09-15 13:40:21 +0000
+++ beeseek/template/css.py 2009-11-12 13:55:22 +0000
@@ -20,3 +20,5 @@
20#pylint: disable-msg=C010320#pylint: disable-msg=C0103
21style = Template('css/style.css', dont_parse=True,21style = Template('css/style.css', dont_parse=True,
22 tags={'content-type': 'text/css'})22 tags={'content-type': 'text/css'})
23style_error = Template('css/style-error.css', dont_parse=True,
24 tags={'content-type': 'text/css'})
2325
=== modified file 'beeseek/template/html.py'
--- beeseek/template/html.py 2009-10-24 12:25:08 +0000
+++ beeseek/template/html.py 2009-11-12 13:55:22 +0000
@@ -21,3 +21,4 @@
21start_page = Template('html/home.html')21start_page = Template('html/home.html')
22search_page = Template('html/search.html')22search_page = Template('html/search.html')
23configuration_page = Template('html/configuration.html')23configuration_page = Template('html/configuration.html')
24error_page = Template('html/error.html')
2425
=== modified file 'beeseek/template/images.py'
--- beeseek/template/images.py 2009-09-15 13:40:21 +0000
+++ beeseek/template/images.py 2009-11-12 13:55:22 +0000
@@ -20,3 +20,5 @@
20#pylint: disable-msg=C010320#pylint: disable-msg=C0103
21logo = Template('images/logo.png', dont_parse=True,21logo = Template('images/logo.png', dont_parse=True,
22 tags={'content-type': 'image/png'})22 tags={'content-type': 'image/png'})
23bars = Template('images/bars.png', dont_parse=True,
24 tags={'content-type': 'image/png'})
2325
=== modified file 'beeseek/ui/__init__.py'
--- beeseek/ui/__init__.py 2009-10-24 12:54:21 +0000
+++ beeseek/ui/__init__.py 2009-11-12 13:55:22 +0000
@@ -33,6 +33,10 @@
33 template = css.style33 template = css.style
34 elif page == '/beeseek:logo.png':34 elif page == '/beeseek:logo.png':
35 template = images.logo35 template = images.logo
36 elif page == '/beeseek:style-error.css':
37 template = css.style_error
38 elif page == '/beeseek:bars.png':
39 template = images.bars
36 else:40 else:
37 return False41 return False
38 data = template.format()42 data = template.format()
3943
=== modified file 'beeseek/web/servers/baseserver.py'
--- beeseek/web/servers/baseserver.py 2009-10-21 17:05:04 +0000
+++ beeseek/web/servers/baseserver.py 2009-11-12 13:55:22 +0000
@@ -191,9 +191,9 @@
191 except StopServing:191 except StopServing:
192 self.stop_serving()192 self.stop_serving()
193 return193 return
194 except StandardError:194 except Exception, exc:
195 try:195 try:
196 self.handle_error(client, requestdata)196 self.handle_error(client, requestdata, exc)
197 except StopProcessing, exc:197 except StopProcessing, exc:
198 close = exc.close198 close = exc.close
199 except StopServing:199 except StopServing:
@@ -220,7 +220,8 @@
220 client.close()220 client.close()
221221
222 @Method.with_default222 @Method.with_default
223 def handle_error(self, client, requestdata): #pylint: disable-msg=W0613223 def handle_error(
224 self, client, requestdata, exc): #pylint: disable-msg=W0613
224 """Called by serve_request() when an exception is raised.225 """Called by serve_request() when an exception is raised.
225226
226 By default, this function raises the exception.227 By default, this function raises the exception.
227228
=== modified file 'beeseek/web/servers/http.py'
--- beeseek/web/servers/http.py 2009-10-21 17:02:40 +0000
+++ beeseek/web/servers/http.py 2009-11-12 13:55:22 +0000
@@ -30,8 +30,9 @@
30from beeseek.web.protocols.http import (30from beeseek.web.protocols.http import (
31 HTTPMethods, HTTPServerApplication, HTTPClientApplication,31 HTTPMethods, HTTPServerApplication, HTTPClientApplication,
32 get_host_port_and_page)32 get_host_port_and_page)
33from beeseek.web.protocols.lowlevel import SSLContext33from beeseek.web.protocols.lowlevel import SocketError, SSLContext
34from beeseek.web.servers.baseserver import BaseServer, StopProcessing34from beeseek.web.servers.baseserver import BaseServer, StopProcessing
35from beeseek.template.html import error_page
35from beeseek.template.javascript import pac36from beeseek.template.javascript import pac
3637
3738
@@ -51,13 +52,11 @@
51 method, page = requestline[:2]52 method, page = requestline[:2]
5253
53 if show_page(client, page):54 if show_page(client, page):
54 return55 pass
55 elif page in ('/search', '/search/'):56 elif page in ('/search', '/search/'):
56 show_start_page(client, method)57 show_start_page(client, method)
57 return True
58 elif page.startswith('/search/'):58 elif page.startswith('/search/'):
59 show_results(client, page)59 show_results(client, page)
60 return True
61 elif page == '/submit-oops' and method == HTTPMethods.POST:60 elif page == '/submit-oops' and method == HTTPMethods.POST:
62 self._save_oops_report(client, headers)61 self._save_oops_report(client, headers)
63 else:62 else:
@@ -240,7 +239,17 @@
240 client.end_response()239 client.end_response()
241 client.flush()240 client.flush()
242241
243 def handle_capacity_limit(self, client):242 def handle_error(self, client, requestdata, exc):
244 """See `BaseServer`."""243 """Show a page describing the error with some useful information."""
245 # TODO Show a message and log the error244 if isinstance(exc, SocketError):
246 raise NotImplementedError245 data = error_page.format(
246 errorname='server-not-found', details=str(exc))
247 headers = instance.http_response_headers.copy()
248 headers['Content-Length'] = str(len(data))
249 headers['Content-Type'] = error_page.template_tags['content-type']
250 client.start_response(404, 'Not found', headers)
251 client.write(data)
252 client.end_response()
253 client.flush()
254 else:
255 raise
247256
=== added file 'templates/css/style-error.css'
--- templates/css/style-error.css 1970-01-01 00:00:00 +0000
+++ templates/css/style-error.css 2009-11-12 13:55:22 +0000
@@ -0,0 +1,47 @@
1body {
2 background-color: #EFEFEF;
3 font-family: sans-serif;
4 font-size: 12pt;
5}
6
7.details {
8 font-size: 9pt;
9}
10
11div#actions {
12 text-align: center;
13}
14
15div#details {
16 /* By default details are hidden. */
17 display: none;
18}
19
20div#warning {
21 border: 2px solid #FAC232;
22 background: #FFFFFF url(/beeseek:bars.png) repeat-x;
23 left: 20%;
24 padding: 0.5em 0 0.5em 1.2em;
25 position: absolute;
26 top: 10%;
27 width: 60%;
28
29 /* Display a round border. */
30 /* TODO The following properties are not W3 standard (and therefore not
31 * TODO supported on all browsers). It may be better to use images. */
32 -moz-border-radius: 30px;
33 -o-border-radius: 30px;
34 -webkit-border-radius: 30px;
35 -ktml-border-radius: 30px;
36}
37
38div#warning h1 {
39 color: #EE8A03;
40 font-size: 20pt;
41}
42
43div#warning a {
44 color: #556D7A;
45 text-decoration: none;
46 font-weight: bold;
47}
048
=== added file 'templates/html/error-messages.xml'
--- templates/html/error-messages.xml 1970-01-01 00:00:00 +0000
+++ templates/html/error-messages.xml 2009-11-12 13:55:22 +0000
@@ -0,0 +1,18 @@
1<beeseek:template content-type="text/html">
2 <beeseek:container id="server-not-found">
3 <beeseek:object id="title">Cannot connect to server</beeseek:object>
4 <beeseek:object id="message">Unable to establish a connection with the server.</beeseek:object>
5 <beeseek:object id="rationale">
6 <p>Possible causes of this issue:</p>
7 <ul>
8 <li>The site could be temporarily unavailable or too busy. Try again
9 in a few moments.</li>
10 <li>If you are unable to load any pages, check your computer's network
11 connection.</li>
12 <li>If your computer or network is protected by a firewall or proxy,
13 make sure that <beeseek:insert type="variable" name="instance.appname" />
14 is permitted to access the Net.</li>
15 </ul>
16 </beeseek:object>
17 </beeseek:container>
18</beeseek:template>
019
=== modified file 'templates/html/error.html'
--- templates/html/error.html 2008-08-27 13:51:34 +0000
+++ templates/html/error.html 2009-11-12 13:55:22 +0000
@@ -1,87 +1,44 @@
1<?xml version="1.0" encoding="UTF-8"?>1<beeseek:template content-type="text/html"><?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">2<html>
3<html xmlns="http://www.w3.org/1999/xhtml">
4 <head>3 <head>
5 <title>4 <title><beeseek:insert type="object" file="html/error-messages.xml" id="%(errorname)s.title" /></title>
6 Error5 <link rel="stylesheet" type="text/css" media="screen" href="/beeseek:style-error.css" />
7 </title>6 <script type="text/javascript">
8 <meta http-equiv="Content-type" content='text/html; charset="UTF-8"' />7 function toggle_details() {
9 <style type="text/css">8 var box_style;
10 body{9 var label;
11 margin: 0;10
12 padding: 0;11 box_style = document.getElementById('details').style;
13 background: #fff;12 label = document.getElementById('details-label');
14 font-family: "Bitstream Vera Sans", "Trebuchet MS", "Trebuchet", "Verdana", "Arial", "Sans-serif";13
15 font-size: 9pt;14 if (box_style.display == 'block') {
16 color: #121212;15 label.innerHTML = 'Technical details';
17 }16 box_style.display = 'none';
1817 } else {
19 h3 {18 label.innerHTML = 'Hide technical details';
20 font-size: 140%;19 box_style.display = 'block';
21 }20 }
2221 }
23 #logo h1{22 </script>
24 position: relative;
25 width: 250px;
26 left: 50%;
27 margin: 0 0 0 -125px;
28 padding: 10px 0 0 0;
29 color: #000;
30 font-size: 20pt;
31 }
32
33 #howto{
34 background: #e6eed3;
35 border: #ffc90f 1px solid;
36 padding: 10px;
37 margin: 20px;
38 font-weight: bold;
39 }
40
41 #howto a{
42 color: #556d7a;
43 }
44
45 #content{
46 border: #ffc90f 1px solid;
47 margin: 0 20px;
48 padding: 0px 20px 0 20px;
49 }
50
51 #traceback{
52 background: #f8f8f8;
53 border: #cccccc 1px solid;
54 margin: 0 0 10px 0;
55 padding: 10px;
56 font-size: 8pt;
57 }
58
59 textarea{
60 background: #f8f8f8;
61 border: none;
62 width:100%;
63 min-height: 300px;
64 }
65 </style>
66 </head>23 </head>
67 <body>24 <body>
68 <div id="header">25 <div id="warning">
69 <div id="logo">26 <h1><beeseek:insert type="object" file="html/error-messages.xml" id="%(errorname)s.title" /></h1>
70 <h1>27 <p><strong><beeseek:insert type="object" file="html/error-messages.xml" id="%(errorname)s.message" /></strong></p>
71 Error28 <beeseek:insert type="object" file="html/error-messages.xml" id="%(errorname)s.rationale" />
72 </h1>29 <div id="actions">
30 <button id="try-again">Try again</button>
31 <button id="search">Search in the Web</button>
73 </div>32 </div>
74 </div>33 <p class="details">
75 <div id="howto">34 <a id="details-label" href="#details" onclick="toggle_details()">Technical details</a>
76 Sorry, an error has occurred. Try to reload this page to solve the problem. If it still occurs, please <a href="https://launchpad.net/honeybee/+filebug">report this bug</a> including the following information. Thanks for your patient!35 </p>
77 </div>36 <div id="details" class="details">
78 <div id="content">37 <pre>
79 <h3>38<beeseek:insert type="variable" name="details" />
80 Traceback:39 </pre>
81 </h3>
82 <div id="traceback">
83 <textarea rows="1" cols="1" readonly="readonly"><![CDATA[$traceback]]></textarea>
84 </div>40 </div>
85 </div>41 </div>
86 </body>42 </body>
87</html>43</html>
44</beeseek:template>
8845
=== added file 'templates/images/bars.png'
89Binary files templates/images/bars.png 1970-01-01 00:00:00 +0000 and templates/images/bars.png 2009-11-12 13:55:22 +0000 differ46Binary files templates/images/bars.png 1970-01-01 00:00:00 +0000 and templates/images/bars.png 2009-11-12 13:55:22 +0000 differ

Subscribers

People subscribed via source and target branches