Skip to content
Snippets Groups Projects
Verified Commit 0a80a6c5 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Improved file parsing

parent 56df916a
Branches
No related tags found
No related merge requests found
......@@ -20,11 +20,11 @@ import (
"fmt"
"html/template"
"log"
"net/url"
"path"
"mime"
"net/http"
"net/url"
"os"
"path"
"strconv"
"strings"
"time"
......@@ -132,17 +132,21 @@ func errorHandler(errorFilesPath string) func(http.ResponseWriter, *http.Request
var file string
for _, ext := range exts {
filePath := fmt.Sprintf("%v/%v%v", errorFilesPath, code, ext)
if _, err := os.Stat(file); os.IsNotExist(err) {
var filePath string
filePath = fmt.Sprintf("%v/%v%v", errorFilesPath, code, ext)
if _, err = os.Stat(filePath); err == nil {
file = filePath
break
}
scode := strconv.Itoa(code)
filePath = fmt.Sprintf("%v/%cxx%v", errorFilesPath, scode[0], ext)
if _, err := os.Stat(file); os.IsNotExist(err) {
continue
}
}
if _, err = os.Stat(filePath); err == nil {
file = filePath
break
}
}
if file == "" {
log.Printf("unexpected error opening file: %v", err)
http.NotFound(w, r)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment