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
No related branches found
No related tags found
No related merge requests found
...@@ -20,11 +20,11 @@ import ( ...@@ -20,11 +20,11 @@ import (
"fmt" "fmt"
"html/template" "html/template"
"log" "log"
"net/url"
"path"
"mime" "mime"
"net/http" "net/http"
"net/url"
"os" "os"
"path"
"strconv" "strconv"
"strings" "strings"
"time" "time"
...@@ -132,17 +132,21 @@ func errorHandler(errorFilesPath string) func(http.ResponseWriter, *http.Request ...@@ -132,17 +132,21 @@ func errorHandler(errorFilesPath string) func(http.ResponseWriter, *http.Request
var file string var file string
for _, ext := range exts { for _, ext := range exts {
filePath := fmt.Sprintf("%v/%v%v", errorFilesPath, code, ext) var filePath string
if _, err := os.Stat(file); os.IsNotExist(err) {
filePath = fmt.Sprintf("%v/%v%v", errorFilesPath, code, ext)
if _, err = os.Stat(filePath); err == nil {
file = filePath
break
}
scode := strconv.Itoa(code) scode := strconv.Itoa(code)
filePath = fmt.Sprintf("%v/%cxx%v", errorFilesPath, scode[0], ext) filePath = fmt.Sprintf("%v/%cxx%v", errorFilesPath, scode[0], ext)
if _, err := os.Stat(file); os.IsNotExist(err) { if _, err = os.Stat(filePath); err == nil {
continue
}
}
file = filePath file = filePath
break break
} }
}
if file == "" { if file == "" {
log.Printf("unexpected error opening file: %v", err) log.Printf("unexpected error opening file: %v", err)
http.NotFound(w, r) 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