Browse Source

Readable template error page

Vova Tkach 6 years ago
parent
commit
8cb9e14b4a
2 changed files with 18 additions and 2 deletions
  1. 4 0
      Makefile
  2. 14 2
      engine/wrapper/wrapper.go

+ 4 - 0
Makefile

@@ -4,8 +4,12 @@ default: debug
 
 debug:
 	go vet ./...
+	gofmt -d ./
 	go build -mod vendor -o ./fave
 
+fix:
+	gofmt -w ./
+
 build: clean
 	@-mkdir ./bin
 	@cd ./bin

+ 14 - 2
engine/wrapper/wrapper.go

@@ -178,10 +178,16 @@ func (this *Wrapper) RenderFrontEnd(tname string, data interface{}) {
 	}
 	this.W.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
 	this.W.Header().Set("Content-Type", "text/html; charset=utf-8")
-	tmpl.Execute(this.W, consts.TmplData{
+	var tpl bytes.Buffer
+	err = tmpl.Execute(&tpl, consts.TmplData{
 		System: utils.GetTmplSystemData(),
 		Data:   data,
 	})
+	if err != nil {
+		utils.SystemErrorPageEngine(this.W, err)
+		return
+	}
+	this.W.Write(tpl.Bytes())
 }
 
 func (this *Wrapper) RenderBackEnd(tcont []byte, data interface{}) {
@@ -192,8 +198,14 @@ func (this *Wrapper) RenderBackEnd(tcont []byte, data interface{}) {
 	}
 	this.W.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
 	this.W.Header().Set("Content-Type", "text/html; charset=utf-8")
-	tmpl.Execute(this.W, consts.TmplData{
+	var tpl bytes.Buffer
+	err = tmpl.Execute(this.W, consts.TmplData{
 		System: utils.GetTmplSystemData(),
 		Data:   data,
 	})
+	if err != nil {
+		utils.SystemErrorPageEngine(this.W, err)
+		return
+	}
+	this.W.Write(tpl.Bytes())
 }