Skip to content

Commit 2bd6ca9

Browse files
committed
Improve handling of content decoding error messages
When dropping or PUTting non-UTF8 encoded textual content the error messages were incomplete or not trapped. Partially fixes #137. Additional changes in TiddlyWeb itself provide better error messages and further discussion required to determine if the server should be willing to decode different types of content.
1 parent 1e89cb1 commit 2bd6ca9

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

tiddlywebplugins/tank/closet.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ def _regular_tiddler(environ, bag_name, input_file, target_name):
9090
content = input_file.file.read()
9191

9292
tiddler = Tiddler(target_name, bag_name)
93-
tiddler.text = content.decode('utf-8')
93+
try:
94+
tiddler.text = content.decode('utf-8')
95+
except UnicodeError as exc:
96+
raise HTTP400('tiddler content should be utf-8 encode: %s' % exc)
9497
tiddler.modifier = username
9598
tiddler.type = input_file.type
9699
store.put(tiddler)

tiddlywebplugins/tank/httperror.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,17 @@ def send_error(environ, start_response, exc, allow=None):
3434
"""
3535
Send the error mesage out via template.
3636
"""
37+
38+
# Construct a message from the exception
39+
if not hasattr(exc, 'args'):
40+
exc.args = ('%s' % self,)
41+
output = []
42+
for arg in exc.args:
43+
output.append('%s' % arg)
44+
3745
error = {
3846
'status': exc.status,
39-
'message': exc.message
47+
'message': ' '.join(output)
4048
}
4149

4250
headers = [('Content-type', 'text/html; charset=utf-8')]

0 commit comments

Comments
 (0)