-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: supports exception page template for theme-side #2925
Conversation
我将尝试在 https://github.com/halo-dev/theme-earth 实现这个模板。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
能否支持缺省的错误模板,而不是默认的 Whitelabel Error Page
,尤其是主题没有适配这些模板的情况很有意义。
缺省的错误页面显示什么呢,是否需要样式设计或者只单纯显示一个 message 和 status code |
显示什么不重要,先能够支持在 Core 中定义缺省错误模板即可。 |
@guqing 可以使用 1.x 的默认模板。 |
ok |
可以 |
@guqing 可以在 PR 描述里面补充一下 error 模板都有哪些数据,不然我等萌新不太容易知道,也方便后续编写主题开发文档。 |
好 写了 |
trace 一般什么情况下会有值呢,我这边估计写错语法啥的似乎 trace 没有内容。 |
trace 是异常堆栈 一般不需要显示到页面,如果 trace 没值可以开启 debug 试一下 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
2.1.x 时,需要更新主题开发文档:halo-dev/docs#144
如果错误模板能够拿到 ProblemDetail 会不会更好呢? |
可以的,非常有道理 |
能否直接将 ProblemDetail 直接当做一个对象给到模板呢,目前会有这样的问题: 我的模板: <!DOCTYPE html>
<html
xmlns:th="https://www.thymeleaf.org"
th:replace="~{modules/layout :: html(title = ${status} + ' | ' + ${#strings.defaultString(title, 'Internal server error')} + ' - ' +${site.title}, header = null, content = ~{::content}, head = null, footer = null, sidebar = null, contentClass = null)}"
>
<th:block th:fragment="content">
<section th:fragment="exception" class="flex items-center dark:bg-gray-900 dark:text-gray-100">
<div class="container mx-auto my-8 flex flex-col items-center justify-center px-5">
<div class="max-w-md text-center">
<h2 class="mb-8 text-9xl font-extrabold dark:text-gray-600" th:text="${status}"></h2>
<p class="mb-8 text-2xl font-semibold md:text-3xl" th:text="${#strings.defaultString(title, 'Internal server error')}"></p>
<a
th:href="@{${site.url}}"
class="whitespace-no-wrap group inline-flex items-center justify-center gap-1 rounded-md border border-gray-200 bg-white px-4 py-1 text-sm font-medium leading-6 text-gray-600 shadow-sm hover:bg-gray-50 focus:shadow-none focus:outline-none dark:border-slate-600 dark:bg-slate-700 dark:text-slate-100 dark:hover:bg-slate-600 dark:hover:text-white"
>
<span class="i-tabler-arrow-left text-lg transition-all group-hover:-translate-x-1"></span>
<span>返回首页</span>
</a>
</div>
</div>
</section>
</th:block>
</html> 由于在引入 目前我不能确定这是 Thymeleaf 的 bug 还是我的写法问题。 |
这恐怕不得行,这是 springboot 约束的 /**
* Render the given error data as a view, using a template view if available or a
* static HTML file if available otherwise. This will return an empty
* {@code Publisher} if none of the above are available.
* @param viewName the view name
* @param responseBody the error response being built
* @param error the error data as a map
* @return a Publisher of the {@link ServerResponse}
*/
protected Mono<ServerResponse> renderErrorView(String viewName, ServerResponse.BodyBuilder responseBody,
Map<String, Object> error) {
if (isTemplateAvailable(viewName)) {
return responseBody.render(viewName, error);
}
Resource resource = resolveResource(viewName);
if (resource != null) {
return responseBody.body(BodyInserters.fromResource(resource));
}
return Mono.empty();
} 除非包裹一个 kv 给这个 error map 为 (String, ProblemDetail) |
可以包装成这样 |
好的 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
新增 404 和 500 的异常模板。适配:halo-dev/halo#2925 <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/207247014-81717c6c-7eae-4819-a940-979df46c56cf.png"> <img width="1920" alt="image" src="https://user-images.githubusercontent.com/21301288/207247066-b5684013-f893-4576-bc5c-bc25c0ce914a.png"> /kind feature ```release-note None ```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: JohnNiang, ruibaby The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind feature
/area core
What this PR does / why we need it:
主题端支持异常模板页面
异常模板必须放在主题目录的
templates/error
目录下:error 模板中具有 model 示例:
Which issue(s) this PR fixes:
Fixes #2690
Special notes for your reviewer:
/cc @halo-dev/sig-halo
Does this PR introduce a user-facing change?