diff options
author | Runxi Yu <me@runxiyu.org> | 2025-03-21 22:38:01 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-03-21 22:38:01 +0800 |
commit | e13bbd0c081e7918c23a84a79fdb842c6fe15a1f (patch) | |
tree | 6a30a4ef814613c52e614d0299ea576d944ed16b /http_server.go | |
parent | Fix Is_file -> IsFile naming (diff) | |
download | forge-e13bbd0c081e7918c23a84a79fdb842c6fe15a1f.tar.gz forge-e13bbd0c081e7918c23a84a79fdb842c6fe15a1f.tar.zst forge-e13bbd0c081e7918c23a84a79fdb842c6fe15a1f.zip |
Add a "Proper" 404 page
Diffstat (limited to 'http_server.go')
-rw-r--r-- | http_server.go | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/http_server.go b/http_server.go index 35b3ca5..c883cdf 100644 --- a/http_server.go +++ b/http_server.go @@ -5,7 +5,6 @@ package main import ( "errors" - "fmt" "net/http" "strconv" "strings" @@ -58,7 +57,7 @@ func (router *forgeHTTPRouter) ServeHTTP(w http.ResponseWriter, r *http.Request) if segments[0] == ":" { if len(segments) < 2 { - http.Error(w, "Blank system endpoint", http.StatusNotFound) + errorPage404(w, params) return } else if len(segments) == 2 && redirectDir(w, r) { return @@ -86,7 +85,7 @@ func (router *forgeHTTPRouter) ServeHTTP(w http.ResponseWriter, r *http.Request) httpHandleGC(w, r, params) return default: - http.Error(w, fmt.Sprintf("Unknown system module type: %s", segments[1]), http.StatusNotFound) + errorPage404(w, params) return } } @@ -119,10 +118,10 @@ func (router *forgeHTTPRouter) ServeHTTP(w http.ResponseWriter, r *http.Request) } httpHandleGroupIndex(w, r, params) case len(segments) == sepIndex+1: - http.Error(w, "Illegal path 1", http.StatusNotImplemented) + errorPage404(w, params) return case len(segments) == sepIndex+2: - http.Error(w, "Illegal path 2", http.StatusNotImplemented) + errorPage404(w, params) return default: moduleType = segments[sepIndex+1] @@ -213,10 +212,12 @@ func (router *forgeHTTPRouter) ServeHTTP(w http.ResponseWriter, r *http.Request) http.Error(w, "Too many parameters", http.StatusBadRequest) } default: - http.Error(w, fmt.Sprintf("Unknown repo feature: %s", repoFeature), http.StatusNotFound) + errorPage404(w, params) + return } default: - http.Error(w, fmt.Sprintf("Unknown module type: %s", moduleType), http.StatusNotFound) + errorPage404(w, params) + return } } } |