Skip to content

Commit

Permalink
Improve error handling
Browse files Browse the repository at this point in the history
- Add theme handling to error pages
- Center error message
  • Loading branch information
martinRenou committed Mar 9, 2022
1 parent d2220dd commit 38b23c2
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
12 changes: 11 additions & 1 deletion share/jupyter/voila/templates/base/error.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
{% extends "page.html" %}

{% block stylesheets %}
{{ super() }}

<style>
.voila-error {
text-align: center;
}
</style>
{% endblock %}

{% block body %}
<div>
<div class="voila-error">
<h1>{{ status_code }}: {{ status_message }}</h1>

{% block error_detail %}
Expand Down
12 changes: 12 additions & 0 deletions share/jupyter/voila/templates/lab/error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "voila/templates/base/error.html" %}

{% block stylesheets %}
{{ super() }}

<style>
body {
background-color: var(--jp-layout-color0);
color: var(--jp-ui-font-color0);
}
</style>
{% endblock %}
26 changes: 25 additions & 1 deletion voila/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from ._version import __version__
from .notebook_renderer import NotebookRenderer
from .query_parameters_handler import QueryStringSocketHandler
from .utils import ENV_VARIABLE
from .utils import ENV_VARIABLE, create_include_assets_functions


class VoilaHandler(JupyterHandler):
Expand Down Expand Up @@ -192,6 +192,30 @@ async def get(self, path=None):
self.write(html)
self.flush()

def render_template(self, name, **ns):
template_arg = (
self.get_argument("voila-template", self.voila_configuration.template)
if self.voila_configuration.allow_template_override == "YES"
else self.voila_configuration.template
)
theme_arg = (
self.get_argument("voila-theme", self.voila_configuration.theme)
if self.voila_configuration.allow_theme_override == "YES"
else self.voila_configuration.theme
)

ns = {
**ns,
**self.template_namespace,
**create_include_assets_functions(
template_arg, self.base_url
),
"theme": theme_arg
}

template = self.get_template(name)
return template.render(**ns)

def redirect_to_file(self, path):
self.redirect(url_path_join(self.base_url, 'voila', 'files', path))

Expand Down

0 comments on commit 38b23c2

Please sign in to comment.