Skip to content

Commit f4921b9

Browse files
authored
Simplify 404/500 page (#31409)
1 parent 6a96deb commit f4921b9

File tree

7 files changed

+39
-19
lines changed

7 files changed

+39
-19
lines changed

public/assets/img/404.png

-4.41 KB
Binary file not shown.

public/assets/img/500.png

-5.11 KB
Binary file not shown.

templates/status/404.tmpl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
{{template "base/head" .}}
22
<div role="main" aria-label="{{.Title}}" class="page-content {{if .IsRepo}}repository{{end}}">
33
{{if .IsRepo}}{{template "repo/header" .}}{{end}}
4-
<div class="ui container tw-text-center">
5-
<img class="tw-max-w-[80vw] tw-py-16" src="{{AssetUrlPrefix}}/img/404.png" alt="404">
6-
<p>{{if .NotFoundPrompt}}{{.NotFoundPrompt}}{{else}}{{ctx.Locale.Tr "error404"}}{{end}}</p>
7-
{{if .NotFoundGoBackURL}}<a class="ui button" href="{{.NotFoundGoBackURL}}">{{ctx.Locale.Tr "go_back"}}</a>{{end}}
4+
<div class="ui container">
5+
<div class="status-page-error">
6+
<div class="status-page-error-title">404 Not Found</div>
7+
<div class="tw-text-center">
8+
<div class="tw-my-4">{{if .NotFoundPrompt}}{{.NotFoundPrompt}}{{else}}{{ctx.Locale.Tr "error404"}}{{end}}</div>
9+
{{if .NotFoundGoBackURL}}
10+
<a class="tw-block tw-my-4" href="{{.NotFoundGoBackURL}}">{{ctx.Locale.Tr "go_back"}}</a>
11+
{{end}}
12+
</div>
13+
</div>
814
</div>
915
</div>
1016
{{template "base/footer" .}}

templates/status/500.tmpl

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,18 @@
3333
<div class="ui container" >
3434
<style> .ui.message.flash-message { text-align: left; } </style>
3535
{{template "base/alert" .}}
36-
</div>
37-
<p class="tw-mt-8 center"><img src="{{AssetUrlPrefix}}/img/500.png" alt="Internal Server Error"></p>
38-
<div class="divider"></div>
39-
<div class="ui container tw-my-8">
40-
{{if .ErrorMsg}}
41-
<p>{{ctx.Locale.Tr "error.occurred"}}:</p>
42-
<pre class="tw-whitespace-pre-wrap tw-break-all">{{.ErrorMsg}}</pre>
43-
{{end}}
44-
<div class="center tw-mt-8">
45-
{{if or .SignedUser.IsAdmin .ShowFooterVersion}}<p>{{ctx.Locale.Tr "admin.config.app_ver"}}: {{AppVer}}</p>{{end}}
46-
{{if .SignedUser.IsAdmin}}<p>{{ctx.Locale.Tr "error.report_message"}}</p>{{end}}
36+
<div class="status-page-error">
37+
<div class="status-page-error-title">500 Internal Server Error</div>
38+
{{if .ErrorMsg}}
39+
<div class="tw-mt-8">
40+
<p>{{ctx.Locale.Tr "error.occurred"}}:</p>
41+
<pre class="tw-whitespace-pre-wrap tw-break-all">{{.ErrorMsg}}</pre>
42+
</div>
43+
{{end}}
44+
<div class="tw-mt-8 tw-text-center">
45+
{{if or .SignedUser.IsAdmin .ShowFooterVersion}}<p>{{ctx.Locale.Tr "admin.config.app_ver"}}: {{AppVer}}</p>{{end}}
46+
{{if .SignedUser.IsAdmin}}<p>{{ctx.Locale.Tr "error.report_message"}}</p>{{end}}
47+
</div>
4748
</div>
4849
</div>
4950
</div>

tests/integration/compare_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"code.gitea.io/gitea/models/db"
1414
"code.gitea.io/gitea/models/unittest"
1515
user_model "code.gitea.io/gitea/models/user"
16+
"code.gitea.io/gitea/modules/test"
1617
repo_service "code.gitea.io/gitea/services/repository"
1718
"code.gitea.io/gitea/tests"
1819

@@ -30,9 +31,9 @@ func TestCompareTag(t *testing.T) {
3031
// A dropdown for both base and head.
3132
assert.Lenf(t, selection.Nodes, 2, "The template has changed")
3233

33-
req = NewRequest(t, "GET", "/user2/repo1/compare/invalid")
34+
req = NewRequest(t, "GET", "/user2/repo1/compare/invalid").SetHeader("Accept", "text/html")
3435
resp = session.MakeRequest(t, req, http.StatusNotFound)
35-
assert.False(t, strings.Contains(resp.Body.String(), "/assets/img/500.png"), "expect 404 page not 500")
36+
assert.True(t, test.IsNormalPageCompleted(resp.Body.String()), "expect 404 page not 500")
3637
}
3738

3839
// Compare with inferred default branch (master)

tests/integration/links_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ func TestLinksNoLogin(t *testing.T) {
3737
"/user2/repo1/projects",
3838
"/user2/repo1/projects/1",
3939
"/user2/repo1/releases/tag/delete-tag", // It's the only one existing record on release.yml which has is_tag: true
40-
"/assets/img/404.png",
41-
"/assets/img/500.png",
4240
"/.well-known/security.txt",
4341
}
4442

web_src/css/base.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,20 @@ img.ui.avatar,
477477
padding-bottom: 80px;
478478
}
479479

480+
.status-page-error {
481+
margin-top: max(45vh - 90px, 80px);
482+
margin-bottom: 80px;
483+
}
484+
485+
.status-page-error-title {
486+
font-size: 48px;
487+
margin-bottom: 14px; /* some elements below may use tw-my-4 or tw-my-8, so use 14px as a minimal margin */
488+
line-height: initial;
489+
text-align: center;
490+
font-weight: var(--font-weight-bold);
491+
color: var(--color-text-light-2);
492+
}
493+
480494
/* add margin below .secondary nav when it is the first child */
481495
.page-content > :first-child.secondary-nav {
482496
margin-bottom: 14px;

0 commit comments

Comments
 (0)