I am using flask
and socket.io
to transmit python
exceptions, and show the exception strings in an html
modal box. The problem is the strings displayed in the modal box has no format, which looks like a long concatenated string with all the exceptions put together,
Traceback (most recent call last): File "/home/user_name/.local/lib/python3.5/site-packages/requests/packages/urllib3/connection.py", line 137, in _new_conn (self.host, self.port), self.timeout, **extra_kw) File "/home/user_name/.local/lib/python3.5/site-packages/requests/packages/urllib3/util/connection.py", line 91, in create_connection raise err File "/home/user_name/.local/lib/python3.5/site-packages/requests/packages/urllib3/util/connection.py", line 81, in create_connection sock.connect(sa) File "/usr/local/lib/python3.5/dist-packages/gevent/_socket3.py", line 301, in connect raise error(err, strerror(err)) ConnectionRefusedError: [Errno 111] Connection refused
and I like it to be displayed like in the python console
,
Traceback (most recent call last):
File "/home/user_name/.local/lib/python3.5/site-packages/requests/packages/urllib3/connection.py", line 137, in _new_conn
(self.host, self.port), self.timeout, **extra_kw)
File "/home/user_name/.local/lib/python3.5/site-packages/requests/packages/urllib3/util/connection.py", line 91, in create_connection
raise err
File "/home/user_name/.local/lib/python3.5/site-packages/requests/packages/urllib3/util/connection.py", line 81, in create_connection
sock.connect(sa)
File "/usr/local/lib/python3.5/dist-packages/gevent/_socket3.py", line 301, in connect
raise error(err, strerror(err))
ConnectionRefusedError: [Errno 111] Connection refused
I am wondering how to achieve that in JavaScript
.
Update
This is my js
code for modal box using <pre>
,
function show_modal(row, column) {
var modal_header = $(".modal-header");
modal_header.text("header_footer");
$(".modal-body p").append("<pre>" + "Traceback (most recent call last): File "/home/user_name/.local/lib/python3.5/site-packages/requests/packages/urllib3/connection.py", line 137, in _new_conn (self.host, self.port), self.timeout, **extra_kw) File "/home/user_name/.local/lib/python3.5/site-packages/requests/packages/urllib3/util/connection.py", line 91, in create_connection raise err File "/home/user_name/.local/lib/python3.5/site-packages/requests/packages/urllib3/util/connection.py", line 81, in create_connection sock.connect(sa) File "/usr/local/lib/python3.5/dist-packages/gevent/_socket3.py", line 301, in connect raise error(err, strerror(err)) ConnectionRefusedError: [Errno 111] Connection refused " + "</pre>");
var modal_footer = $(".modal-footer");
modal_footer.text("header_footer");
modal.style.display = "block";
}