Display an error if panic
All checks were successful
CI / build (push) Successful in 4m46s

This commit is contained in:
Fijxu 2024-10-31 16:29:30 -03:00
parent 900b6bd3e7
commit fa0c7e9373
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4
2 changed files with 9 additions and 0 deletions

View file

@ -167,6 +167,8 @@ func requestPerMinute() {
func beforeAll(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {
defer panicHandler(w)
if req.Method != "GET" && req.Method != "HEAD" {
io.WriteString(w, "Only GET and HEAD requests are allowed.")
return

View file

@ -55,3 +55,10 @@ func RelativeUrl(in string) (newurl string) {
segment_url.Path = path_prefix + segment_url.Path
return segment_url.RequestURI()
}
func panicHandler(w http.ResponseWriter) {
if r := recover(); r != nil {
log.Printf("Panic: %v", r)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
}
}