aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--http_error_page.go11
-rw-r--r--http_handle_group_index.go4
-rw-r--r--http_handle_repo_contrib_one.go2
-rw-r--r--http_handle_users.go4
-rw-r--r--http_server.go6
-rw-r--r--templates/403.tmpl25
-rw-r--r--templates/501.tmpl24
7 files changed, 68 insertions, 8 deletions
diff --git a/http_error_page.go b/http_error_page.go
index 0ddf055..355b504 100644
--- a/http_error_page.go
+++ b/http_error_page.go
@@ -18,6 +18,12 @@ func errorPage400(w http.ResponseWriter, params map[string]any, msg string) {
_ = templates.ExecuteTemplate(w, "400", params)
}
+func errorPage403(w http.ResponseWriter, params map[string]any, msg string) {
+ w.WriteHeader(http.StatusForbidden)
+ params["complete_error_msg"] = msg
+ _ = templates.ExecuteTemplate(w, "403", params)
+}
+
func errorPage451(w http.ResponseWriter, params map[string]any, msg string) {
w.WriteHeader(http.StatusUnavailableForLegalReasons)
params["complete_error_msg"] = msg
@@ -29,3 +35,8 @@ func errorPage500(w http.ResponseWriter, params map[string]any, msg string) {
params["complete_error_msg"] = msg
_ = templates.ExecuteTemplate(w, "500", params)
}
+
+func errorPage501(w http.ResponseWriter, params map[string]any) {
+ w.WriteHeader(http.StatusNotImplemented)
+ _ = templates.ExecuteTemplate(w, "501", params)
+}
diff --git a/http_handle_group_index.go b/http_handle_group_index.go
index d8e496f..eef6682 100644
--- a/http_handle_group_index.go
+++ b/http_handle_group_index.go
@@ -79,7 +79,7 @@ func httpHandleGroupIndex(writer http.ResponseWriter, request *http.Request, par
if request.Method == http.MethodPost {
if !directAccess {
- http.Error(writer, "You do not have direct access to this group", http.StatusForbidden)
+ errorPage403(writer, params, "You do not have direct access to this group")
return
}
@@ -87,7 +87,7 @@ func httpHandleGroupIndex(writer http.ResponseWriter, request *http.Request, par
repoDesc := request.FormValue("repo_desc")
contribReq := request.FormValue("repo_contrib")
if repoName == "" {
- http.Error(writer, "Repo name is required", http.StatusBadRequest)
+ errorPage400(writer, params, "Repo name is required")
return
}
diff --git a/http_handle_repo_contrib_one.go b/http_handle_repo_contrib_one.go
index 4a5f6b8..134f50b 100644
--- a/http_handle_repo_contrib_one.go
+++ b/http_handle_repo_contrib_one.go
@@ -26,7 +26,7 @@ func httpHandleRepoContribOne(writer http.ResponseWriter, request *http.Request,
mrIDStr = params["mr_id"].(string)
mrIDInt64, err := strconv.ParseInt(mrIDStr, 10, strconv.IntSize)
if err != nil {
- http.Error(writer, "Merge request ID not an integer: "+err.Error(), http.StatusBadRequest)
+ errorPage400(writer, params, "Merge request ID not an integer")
return
}
mrIDInt = int(mrIDInt64)
diff --git a/http_handle_users.go b/http_handle_users.go
index 2570de7..ba6755d 100644
--- a/http_handle_users.go
+++ b/http_handle_users.go
@@ -7,6 +7,6 @@ import (
"net/http"
)
-func httpHandleUsers(writer http.ResponseWriter, _ *http.Request, _ map[string]any) {
- http.Error(writer, "Not implemented", http.StatusNotImplemented)
+func httpHandleUsers(writer http.ResponseWriter, _ *http.Request, params map[string]any) {
+ errorPage501(writer, params)
}
diff --git a/http_server.go b/http_server.go
index 2bf1587..c8528fe 100644
--- a/http_server.go
+++ b/http_server.go
@@ -35,7 +35,7 @@ func (router *forgeHTTPRouter) ServeHTTP(writer http.ResponseWriter, request *ht
params := make(map[string]any)
if segments, _, err = parseReqURI(request.RequestURI); err != nil {
- http.Error(writer, err.Error(), http.StatusBadRequest)
+ errorPage400(writer, params, "Error parsing request URI: "+err.Error())
return
}
dirMode := false
@@ -212,7 +212,7 @@ func (router *forgeHTTPRouter) ServeHTTP(writer http.ResponseWriter, request *ht
httpHandleRepoRaw(writer, request, params)
case "log":
if len(segments) > sepIndex+4 {
- http.Error(writer, "Too many parameters", http.StatusBadRequest)
+ errorPage400(writer, params, "Too many parameters")
return
}
if redirectDir(writer, request) {
@@ -236,7 +236,7 @@ func (router *forgeHTTPRouter) ServeHTTP(writer http.ResponseWriter, request *ht
params["mr_id"] = segments[sepIndex+4]
httpHandleRepoContribOne(writer, request, params)
default:
- http.Error(writer, "Too many parameters", http.StatusBadRequest)
+ errorPage400(writer, params, "Too many parameters")
}
default:
errorPage404(writer, params)
diff --git a/templates/403.tmpl b/templates/403.tmpl
new file mode 100644
index 0000000..62a2654
--- /dev/null
+++ b/templates/403.tmpl
@@ -0,0 +1,25 @@
+{{/*
+ SPDX-License-Identifier: AGPL-3.0-only
+ SPDX-FileContributor: Runxi Yu <https://runxiyu.org>
+*/}}
+{{- define "403" -}}
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ {{- template "head_common" . -}}
+ <title>403 Forbidden &ndash; {{ .global.forge_title }}</title>
+ </head>
+ <body class="403">
+ {{- template "header" . -}}
+ <div class="padding-wrapper complete-error-page">
+ <h1>403 Forbidden</h1>
+ <p>{{- .complete_error_msg -}}</p>
+ <hr />
+ <address>Lindenii Forge</address>
+ </div>
+ <footer>
+ {{- template "footer" . -}}
+ </footer>
+ </body>
+</html>
+{{- end -}}
diff --git a/templates/501.tmpl b/templates/501.tmpl
new file mode 100644
index 0000000..b49bc36
--- /dev/null
+++ b/templates/501.tmpl
@@ -0,0 +1,24 @@
+{{/*
+ SPDX-License-Identifier: AGPL-3.0-only
+ SPDX-FileContributor: Runxi Yu <https://runxiyu.org>
+*/}}
+{{- define "501" -}}
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ {{- template "head_common" . -}}
+ <title>501 Not Implemented &ndash; {{ .global.forge_title }}</title>
+ </head>
+ <body class="501">
+ {{- template "header" . -}}
+ <div class="padding-wrapper complete-error-page">
+ <h1>501 Not Implemented</h1>
+ <hr />
+ <address>Lindenii Forge</address>
+ </div>
+ <footer>
+ {{- template "footer" . -}}
+ </footer>
+ </body>
+</html>
+{{- end -}}