diff options
author | r <r@freesoftwareextremist.com> | 2021-04-03 06:39:06 +0000 |
---|---|---|
committer | r <r@freesoftwareextremist.com> | 2021-04-03 06:40:32 +0000 |
commit | 2cb6a515ac019bf5621a4d5bd54cf388f5d65e20 (patch) | |
tree | 5b7e92867a826f6c5a7fd792d8ca6432132140a2 | |
parent | 089d4ac50026a9ec20746e59588df077b7d6ade8 (diff) | |
download | bloat-2cb6a515ac019bf5621a4d5bd54cf388f5d65e20.tar.gz bloat-2cb6a515ac019bf5621a4d5bd54cf388f5d65e20.zip |
Update error page
- Add retry button for GET requests
- Only show signin button when it's a session error
-rw-r--r-- | renderer/model.go | 4 | ||||
-rw-r--r-- | service/service.go | 10 | ||||
-rw-r--r-- | service/transport.go | 8 | ||||
-rw-r--r-- | templates/error.tmpl | 11 |
4 files changed, 23 insertions, 10 deletions
diff --git a/renderer/model.go b/renderer/model.go index 6b27998..d6cd6f3 100644 --- a/renderer/model.go +++ b/renderer/model.go @@ -34,7 +34,9 @@ type NavData struct { type ErrorData struct { *CommonData - Error string + Err string + Retry bool + SessionErr bool } type HomePageData struct { diff --git a/service/service.go b/service/service.go index 1028765..a29345e 100644 --- a/service/service.go +++ b/service/service.go @@ -109,15 +109,21 @@ func (s *service) cdata(c *client, title string, count int, rinterval int, return } -func (s *service) ErrorPage(c *client, err error) error { +func (s *service) ErrorPage(c *client, err error, retry bool) error { var errStr string + var sessionErr bool if err != nil { errStr = err.Error() + if err == errInvalidSession || err == errInvalidCSRFToken { + sessionErr = true + } } cdata := s.cdata(nil, "error", 0, 0, "") data := &renderer.ErrorData{ CommonData: cdata, - Error: errStr, + Err: errStr, + Retry: retry, + SessionErr: sessionErr, } return s.renderer.Render(c.rctx, c.w, renderer.ErrorPage, data) } diff --git a/service/transport.go b/service/transport.go index 317ce5b..50bf9be 100644 --- a/service/transport.go +++ b/service/transport.go @@ -62,11 +62,11 @@ func redirect(c *client, url string) { func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { r := mux.NewRouter() - writeError := func(c *client, err error, t int) { + writeError := func(c *client, err error, t int, retry bool) { switch t { case HTML: c.w.WriteHeader(http.StatusInternalServerError) - s.ErrorPage(c, err) + s.ErrorPage(c, err, retry) case JSON: c.w.WriteHeader(http.StatusInternalServerError) json.NewEncoder(c.w).Encode(map[string]string{ @@ -110,13 +110,13 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { err = authenticate(c, at) if err != nil { - writeError(c, err, rt) + writeError(c, err, rt, req.Method == http.MethodGet) return } err = f(c) if err != nil { - writeError(c, err, rt) + writeError(c, err, rt, req.Method == http.MethodGet) return } } diff --git a/templates/error.tmpl b/templates/error.tmpl index fc925ca..c8da1e6 100644 --- a/templates/error.tmpl +++ b/templates/error.tmpl @@ -2,10 +2,15 @@ {{template "header.tmpl" (WithContext .CommonData $.Ctx)}} <div class="page-title"> Error </div> -<div class="error-text"> {{.Error}} </div> +<div class="error-text"> {{.Err}} </div> <div> - <a href="/timeline/home">Home</a> - <a href="/signin" target="_top">Sign In</a> + <a href="/timeline/home">home</a> + {{if .Retry}} + <a href="{{$.Ctx.Referrer}}">retry</a> + {{end}} + {{if .SessionErr}} + <a href="/signin" target="_top">signin</a> + {{end}} </div> {{template "footer.tmpl"}} |