Merge pull request #17046 from surajshetty3416/fix-error-page

fix: Catch any exception and show proper error page
This commit is contained in:
Suraj Shetty 2022-06-01 18:00:46 +05:30 committed by GitHub
commit 58d0bcd736
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 41 additions and 36 deletions

View file

@ -125,6 +125,10 @@
align-items: center;
}
.page_content {
min-height: 50vh;
}
.breadcrumb-container {
margin-top: 1rem;
padding-top: 0.25rem;

View file

@ -2,33 +2,32 @@
background-color: var(--bg-color);
}
.page-card {
max-width: 360px;
padding: 15px;
margin: 70px auto;
border-radius: 4px;
background-color: var(--fg-color);
/* box-shadow: var(--shadow-base); */
max-width: 360px;
padding: 15px;
margin: 70px auto;
border-radius: 4px;
background-color: var(--fg-color);
box-shadow: var(--shadow-base);
}
.for-reset-password {
margin: 80px 0;
margin: 80px 0;
}
.for-reset-password .page-card {
border: 0;
max-width: 450px;
margin: auto;
border-radius: 10px;
border: 0;
max-width: 450px;
margin: auto;
border-radius: var(--border-radius-md);
padding: 40px 60px;
}
@media (min-width: 567px) {
@media (max-width: 425px) {
.for-reset-password .page-card {
box-shadow: var(--shadow-base);
padding: 40px 60px;
box-shadow: none;
background: none;
padding: 0px;
}
}

View file

@ -118,7 +118,7 @@ class TestWebsite(unittest.TestCase):
def test_error_page(self):
set_request(method="GET", path="/_test/problematic_page")
response = get_response()
self.assertEqual(response.status_code, 500)
self.assertEqual(response.status_code, 417)
def test_login(self):
set_request(method="GET", path="/login")

View file

@ -5,7 +5,13 @@ class ErrorPage(TemplatePage):
def __init__(self, path=None, http_status_code=None, exception=None):
path = "error"
super().__init__(path=path, http_status_code=http_status_code)
self.http_status_code = getattr(exception, "http_status_code", None) or http_status_code or 500
self.exception = exception
def can_render(self):
return True
def init_context(self):
super().init_context()
self.context.http_status_code = getattr(self.exception, "http_status_code", None) or 500
self.context.error_title = getattr(self.exception, "title", None)
self.context.error_message = getattr(self.exception, "message", None)

View file

@ -212,19 +212,13 @@ class TemplatePage(BaseTemplatePage):
def run_pymodule_method(self, method_name):
if hasattr(self.pymodule, method_name):
try:
import inspect
import inspect
method = getattr(self.pymodule, method_name)
if inspect.getfullargspec(method).args:
return method(self.context)
else:
return method()
except (frappe.PermissionError, frappe.DoesNotExistError, frappe.Redirect):
raise
except Exception:
if not frappe.flags.in_migrate:
frappe.errprint(frappe.utils.get_traceback())
method = getattr(self.pymodule, method_name)
if inspect.getfullargspec(method).args:
return method(self.context)
else:
return method()
def render_template(self):
if self.template_path.endswith("min.js"):

View file

@ -23,15 +23,15 @@
<script></script>
<div class="page-card">
<div class="page-card-head">
<span class="indicator red">{{_("Uncaught Server Exception")}}</span>
<span class="indicator red">{{ error_title }}</span>
</div>
<p>{{_("There was an error building this page")}}</p>
<p>{{ error_message }}</p>
<div>
<a href="/" class="btn btn-primary btn-sm">{{ _("Home") }}</a>
</div>
</div>
<p class="text-muted text-center small" style="margin-top: -20px;">
{{ _("Error Code: {0}").format('500') }}
{{ _("Error Code: {0}").format(http_status_code) }}
</p>
<div class="text-center mt-3">
<button class="btn btn-xs btn-link text-muted small view-error" >{{ _("Show Traceback") if not dev_server else _("Hide Traceback") }}</a>

View file

@ -1,6 +1,7 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: MIT. See LICENSE
import frappe
from frappe import _
no_cache = 1
@ -8,7 +9,8 @@ no_cache = 1
def get_context(context):
if frappe.flags.in_migrate:
return
context.http_status_code = 500
print(frappe.get_traceback())
context.error_title = context.error_title or _("Uncaught Server Exception")
context.error_message = context.error_message or _("There was an error building this page")
return {"error": frappe.get_traceback().replace("<", "&lt;").replace(">", "&gt;")}