Commit 565d0cca authored by Jacob Vosmaer's avatar Jacob Vosmaer

Merge branch 'dev-500' into 'master'

Do not show error pages in development mode



See merge request !24
parents 165a1a4e 941318d3
...@@ -59,7 +59,10 @@ func (s *errorPageResponseWriter) Flush() { ...@@ -59,7 +59,10 @@ func (s *errorPageResponseWriter) Flush() {
s.WriteHeader(http.StatusOK) s.WriteHeader(http.StatusOK)
} }
func handleRailsError(documentRoot *string, handler serviceHandleFunc) serviceHandleFunc { func handleRailsError(documentRoot *string, enabled *bool, handler serviceHandleFunc) serviceHandleFunc {
if !*enabled {
return handler
}
return func(w http.ResponseWriter, r *gitRequest) { return func(w http.ResponseWriter, r *gitRequest) {
rw := errorPageResponseWriter{ rw := errorPageResponseWriter{
rw: w, rw: w,
......
...@@ -22,7 +22,8 @@ func TestIfErrorPageIsPresented(t *testing.T) { ...@@ -22,7 +22,8 @@ func TestIfErrorPageIsPresented(t *testing.T) {
w := httptest.NewRecorder() w := httptest.NewRecorder()
handleRailsError(&dir, func(w http.ResponseWriter, r *gitRequest) { enabled := true
handleRailsError(&dir, &enabled, func(w http.ResponseWriter, r *gitRequest) {
w.WriteHeader(404) w.WriteHeader(404)
fmt.Fprint(w, "Not Found") fmt.Fprint(w, "Not Found")
})(w, nil) })(w, nil)
...@@ -42,7 +43,8 @@ func TestIfErrorPassedIfNoErrorPageIsFound(t *testing.T) { ...@@ -42,7 +43,8 @@ func TestIfErrorPassedIfNoErrorPageIsFound(t *testing.T) {
w := httptest.NewRecorder() w := httptest.NewRecorder()
errorResponse := "ERROR" errorResponse := "ERROR"
handleRailsError(&dir, func(w http.ResponseWriter, r *gitRequest) { enabled := true
handleRailsError(&dir, &enabled, func(w http.ResponseWriter, r *gitRequest) {
w.WriteHeader(404) w.WriteHeader(404)
fmt.Fprint(w, errorResponse) fmt.Fprint(w, errorResponse)
})(w, nil) })(w, nil)
...@@ -51,3 +53,27 @@ func TestIfErrorPassedIfNoErrorPageIsFound(t *testing.T) { ...@@ -51,3 +53,27 @@ func TestIfErrorPassedIfNoErrorPageIsFound(t *testing.T) {
assertResponseCode(t, w, 404) assertResponseCode(t, w, 404)
assertResponseBody(t, w, errorResponse) assertResponseBody(t, w, errorResponse)
} }
func TestIfErrorPageIsIgnoredInDevelopment(t *testing.T) {
dir, err := ioutil.TempDir("", "error_page")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)
errorPage := "ERROR"
ioutil.WriteFile(filepath.Join(dir, "500.html"), []byte(errorPage), 0600)
w := httptest.NewRecorder()
enabled := false
serverError := "Interesting Server Error"
handleRailsError(&dir, &enabled, func(w http.ResponseWriter, r *gitRequest) {
w.WriteHeader(500)
fmt.Fprint(w, serverError)
})(w, nil)
w.Flush()
assertResponseCode(t, w, 500)
assertResponseBody(t, w, serverError)
}
...@@ -90,7 +90,7 @@ var httpRoutes = [...]httpRoute{ ...@@ -90,7 +90,7 @@ var httpRoutes = [...]httpRoute{
handleServeFile(documentRoot, CacheExpireMax, handleServeFile(documentRoot, CacheExpireMax,
handleDevelopmentMode(developmentMode, handleDevelopmentMode(developmentMode,
handleDeployPage(documentRoot, handleDeployPage(documentRoot,
handleRailsError(documentRoot, handleRailsError(documentRoot, developmentMode,
proxyRequest, proxyRequest,
), ),
), ),
...@@ -102,7 +102,7 @@ var httpRoutes = [...]httpRoute{ ...@@ -102,7 +102,7 @@ var httpRoutes = [...]httpRoute{
httpRoute{"", nil, httpRoute{"", nil,
handleServeFile(documentRoot, CacheDisabled, handleServeFile(documentRoot, CacheDisabled,
handleDeployPage(documentRoot, handleDeployPage(documentRoot,
handleRailsError(documentRoot, handleRailsError(documentRoot, developmentMode,
proxyRequest, proxyRequest,
), ),
), ),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment