mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
views: Show exception details with the utility to show errors
- Instead of showing traceback details only for action exceptions, show them for normal exceptions also. - Also adjust the gap between the error message and the preformatted text to make it appear better. Tests: - Alter code to raise an exception with the utility. See that details are as expected. - Raise an exception in a privileged action, ensure that the details shown as before. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
parent
40e00423a8
commit
59a0a3b25f
@ -6,6 +6,7 @@ Main FreedomBox views.
|
||||
import datetime
|
||||
import random
|
||||
import time
|
||||
import traceback
|
||||
import urllib.parse
|
||||
|
||||
from django.contrib import messages
|
||||
@ -116,17 +117,20 @@ def messages_error(request, message, exception):
|
||||
If an exception can show HTML message, handle is separately.
|
||||
"""
|
||||
if hasattr(exception, 'get_html_message'):
|
||||
collapse_id = 'error-details-' + str(random.randint(0, 10**9))
|
||||
message = format_html(
|
||||
'{message} <a href="#" class="dropdown-toggle" '
|
||||
'data-bs-toggle="collapse" data-bs-target="#{collapse_id}" '
|
||||
'aria-expanded="false" aria-controls="{collapse_id}">'
|
||||
'Details</a><pre class="collapse" '
|
||||
'id="{collapse_id}"><code>{html_message}</code></pre>',
|
||||
message=message, html_message=exception.get_html_message(),
|
||||
collapse_id=collapse_id)
|
||||
html_message = exception.get_html_message()
|
||||
else:
|
||||
exception_lines = traceback.format_exception(exception)
|
||||
html_message = ''.join(exception_lines)
|
||||
|
||||
messages.error(request, message)
|
||||
collapse_id = 'error-details-' + str(random.randint(0, 10**9))
|
||||
formatted_message = format_html(
|
||||
'{message} <a href="#" class="dropdown-toggle" '
|
||||
'data-bs-toggle="collapse" data-bs-target="#{collapse_id}" '
|
||||
'aria-expanded="false" aria-controls="{collapse_id}">'
|
||||
'Details</a><pre class="collapse" '
|
||||
'id="{collapse_id}"><code>{html_message}</code></pre>',
|
||||
message=message, html_message=html_message, collapse_id=collapse_id)
|
||||
messages.error(request, formatted_message)
|
||||
|
||||
|
||||
def _get_redirect_url_from_param(request):
|
||||
|
||||
@ -343,6 +343,10 @@ html {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.alert pre {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
/* Tags */
|
||||
.tag {
|
||||
--bs-btn-padding-y: 0.25rem; /* Make the badge shorter */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user