79
84
just used to catch exceptions.
80
85
Takes both an IVLE request and an Apache req.
87
# Hack? Try and get the user login early just in case we throw an error
88
# (most likely 404) to stop us seeing not logged in even when we are.
89
req.user = login.get_user_details(req)
82
91
# Check req.app to see if it is valid. 404 if not.
83
92
if req.app is not None and req.app not in conf.apps.app_url:
84
93
# Maybe it is a special app!
145
154
# When done, write out the HTML footer if the app has requested it
146
155
if req.write_html_head_foot:
156
# Show the console if required
157
if logged_in and app.useconsole:
158
plugins.console.present(req, windowpane=True)
147
159
html.write_html_foot(req)
149
161
# Note: Apache will not write custom HTML error messages here.
171
183
the IVLE request is created.
173
185
req.content_type = "text/html"
186
logfile = os.path.join(conf.conf.log_path, 'ivle_error.log')
174
188
# For some reason, some versions of mod_python have "_server" instead of
175
189
# "main_server". So we check for both.
186
200
except AttributeError:
188
202
req.status = apache.HTTP_INTERNAL_SERVER_ERROR
204
login = req.user.login
205
except AttributeError:
210
logging.basicConfig(level=logging.INFO,
211
format='%(asctime)s %(levelname)s: ' +
212
'(HTTP: ' + str(req.status) +
213
', Ref: ' + str(login) + '@' +
214
str(socket.gethostname()) + str(req.uri) +
220
logging.debug('Logging Unhandled Exception')
189
222
# We handle 3 types of error.
190
223
# IVLEErrors with 4xx response codes (client error).
191
224
# IVLEErrors with 5xx response codes (handled server error).
199
232
# IVLEErrors with 4xx response codes are client errors.
200
233
# Therefore, these have a "nice" response (we even coat it in the IVLE
201
234
# HTML wrappers).
202
236
req.write_html_head_foot = True
203
237
req.write('<div id="ivle_padding">\n')
217
251
req.write("<p>%s</p>\n" % cgi.escape(msg))
219
253
req.write("<p>An unknown error occured.</p>\n")
256
logging.info(str(msg))
220
258
req.write("<p>(HTTP error code %d)</p>\n" % httpcode)
260
req.write("<p>Warning: Could not open Error Log: '%s'</p>\n"
261
%cgi.escape(logfile))
221
262
req.write('</div>\n')
223
264
# A "bad" error message. We shouldn't get here unless IVLE
227
268
# If this is a non-4xx IVLEError, get the message and httpcode and
228
269
# make the error message a bit nicer (but still include the
231
codename, msg = req.get_http_codename(httpcode)
232
except AttributeError:
233
codename, msg = None, None
234
# Override the default message with the supplied one,
236
if hasattr(exc_value, 'message') and exc_value.message is not None:
237
msg = exc_value.message
238
# Prepend the exception type
239
if exc_type != util.IVLEError:
240
msg = exc_type.__name__ + ": " + msg
271
# We also need to special-case IVLEJailError, as we can get another
272
# almost-exception out of it.
274
codename, msg = None, None
276
if exc_type is util.IVLEJailError:
277
msg = exc_value.type_str + ": " + exc_value.message
278
tb = 'Exception information extracted from IVLEJailError:\n'
279
tb += urllib.unquote(exc_value.info)
282
codename, msg = req.get_http_codename(httpcode)
283
except AttributeError:
285
# Override the default message with the supplied one,
287
if hasattr(exc_value, 'message') and exc_value.message is not None:
288
msg = exc_value.message
289
# Prepend the exception type
290
if exc_type != util.IVLEError:
291
msg = exc_type.__name__ + ": " + msg
293
tb = ''.join(traceback.format_exception(exc_type, exc_value,
297
logging.error('%s\n%s'%(str(msg), tb))
242
299
req.write("""<html>
243
300
<head><title>IVLE Internal Server Error</title></head>
259
316
administrator). Include the following information:</p>
260
317
""" % (cgi.escape(admin_email), cgi.escape(admin_email)))
262
tb_print = cStringIO.StringIO()
263
traceback.print_exception(exc_type, exc_value, exc_traceback,
266
req.write(cgi.escape(tb_print.getvalue()))
267
req.write("</pre>\n</body>\n")
319
req.write("<pre>\n%s\n</pre>\n"%cgi.escape(tb))
321
req.write("<p>Warning: Could not open Error Log: '%s'</p>\n"
322
%cgi.escape(logfile))