From 6cff08ed36d9dafa81a991baa2966c55ef5467ee Mon Sep 17 00:00:00 2001 From: Janne Koschinski <janne@kuschku.de> Date: Mon, 11 Mar 2019 21:59:45 +0100 Subject: [PATCH] Attempt to fix error handling --- main.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index ac7abcf..60625a0 100644 --- a/main.go +++ b/main.go @@ -126,22 +126,22 @@ func errorHandler(errorFilesPath string) func(http.ResponseWriter, *http.Request if err != nil { code = 404 log.Printf("unexpected error reading return code: %v. Using %v", err, code) + err = nil } w.WriteHeader(code) var file string for _, ext := range exts { filePath := fmt.Sprintf("%v/%v%v", errorFilesPath, code, ext) - if _, err := os.Stat(file); os.IsExist(err) { - file = filePath - break - } - scode := strconv.Itoa(code) - filePath = fmt.Sprintf("%v/%cxx%v", errorFilesPath, scode[0], ext) - if _, err := os.Stat(file); os.IsExist(err) { - file = filePath - break + if _, err := os.Stat(file); os.IsNotExist(err) { + scode := strconv.Itoa(code) + filePath = fmt.Sprintf("%v/%cxx%v", errorFilesPath, scode[0], ext) + if _, err := os.Stat(file); os.IsExist(err) { + continue + } } + file = filePath + break } if file == "" { log.Printf("unexpected error opening file: %v", err) -- GitLab