Commit 941318d3 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Do not show error pages in development mode

parent 165a1a4e
......@@ -59,7 +59,10 @@ func (s *errorPageResponseWriter) Flush() {
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) {
rw := errorPageResponseWriter{
rw: w,
......
......@@ -22,7 +22,8 @@ func TestIfErrorPageIsPresented(t *testing.T) {
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)
fmt.Fprint(w, "Not Found")
})(w, nil)
......@@ -42,7 +43,8 @@ func TestIfErrorPassedIfNoErrorPageIsFound(t *testing.T) {
w := httptest.NewRecorder()
errorResponse := "ERROR"
handleRailsError(&dir, func(w http.ResponseWriter, r *gitRequest) {
enabled := true
handleRailsError(&dir, &enabled, func(w http.ResponseWriter, r *gitRequest) {
w.WriteHeader(404)
fmt.Fprint(w, errorResponse)
})(w, nil)
......@@ -51,3 +53,27 @@ func TestIfErrorPassedIfNoErrorPageIsFound(t *testing.T) {
assertResponseCode(t, w, 404)
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{
handleServeFile(documentRoot, CacheExpireMax,
handleDevelopmentMode(developmentMode,
handleDeployPage(documentRoot,
handleRailsError(documentRoot,
handleRailsError(documentRoot, developmentMode,
proxyRequest,
),
),
......@@ -102,7 +102,7 @@ var httpRoutes = [...]httpRoute{
httpRoute{"", nil,
handleServeFile(documentRoot, CacheDisabled,
handleDeployPage(documentRoot,
handleRailsError(documentRoot,
handleRailsError(documentRoot, developmentMode,
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