From 2256e23c9ef7295b0001b1723be491254bfe73fe Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 2 Feb 2018 07:29:11 -0600 Subject: ABC-153: don't use http redirects with 4xx/5xx status codes (#8178) * don't use http redirects with 4xx/5xx status codes * minor html syntax fix --- utils/api.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'utils') diff --git a/utils/api.go b/utils/api.go index 48382d1fe..005c3284b 100644 --- a/utils/api.go +++ b/utils/api.go @@ -4,6 +4,8 @@ package utils import ( + "fmt" + "html/template" "net/http" "net/url" "strings" @@ -31,18 +33,21 @@ func OriginChecker(allowedOrigins string) func(*http.Request) bool { } func RenderWebError(err *model.AppError, w http.ResponseWriter, r *http.Request) { - message := err.Message - details := err.DetailedError - status := http.StatusTemporaryRedirect if err.StatusCode != http.StatusInternalServerError { status = err.StatusCode } - http.Redirect( - w, - r, - "/error?message="+url.QueryEscape(message)+ - "&details="+url.QueryEscape(details), - status) + destination := strings.TrimRight(GetSiteURL(), "/") + "/error?message=" + url.QueryEscape(err.Message) + if status >= 300 && status < 400 { + http.Redirect(w, r, destination, status) + return + } + + w.WriteHeader(status) + fmt.Fprintln(w, ``) + fmt.Fprintln(w, ``) + fmt.Fprintln(w, ``) + fmt.Fprintln(w, `...`) + fmt.Fprintln(w, ``) } -- cgit v1.2.3-1-g7c22