server: add error HTML templates with error description.
This commit is contained in:
@@ -17,6 +17,7 @@ const (
|
||||
tmplLogin = "login.html"
|
||||
tmplPassword = "password.html"
|
||||
tmplOOB = "oob.html"
|
||||
tmplError = "error.html"
|
||||
)
|
||||
|
||||
var requiredTmpls = []string{
|
||||
@@ -24,6 +25,7 @@ var requiredTmpls = []string{
|
||||
tmplLogin,
|
||||
tmplPassword,
|
||||
tmplOOB,
|
||||
tmplError,
|
||||
}
|
||||
|
||||
type templates struct {
|
||||
@@ -31,6 +33,7 @@ type templates struct {
|
||||
approvalTmpl *template.Template
|
||||
passwordTmpl *template.Template
|
||||
oobTmpl *template.Template
|
||||
errorTmpl *template.Template
|
||||
}
|
||||
|
||||
type webConfig struct {
|
||||
@@ -156,6 +159,7 @@ func loadTemplates(c webConfig, templatesDir string) (*templates, error) {
|
||||
approvalTmpl: tmpls.Lookup(tmplApproval),
|
||||
passwordTmpl: tmpls.Lookup(tmplPassword),
|
||||
oobTmpl: tmpls.Lookup(tmplOOB),
|
||||
errorTmpl: tmpls.Lookup(tmplError),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -222,6 +226,14 @@ func (t *templates) oob(w http.ResponseWriter, code string) error {
|
||||
return renderTemplate(w, t.oobTmpl, data)
|
||||
}
|
||||
|
||||
func (t *templates) err(w http.ResponseWriter, errType string, errMsg string) error {
|
||||
data := struct {
|
||||
ErrType string
|
||||
ErrMsg string
|
||||
}{errType, errMsg}
|
||||
return renderTemplate(w, t.errorTmpl, data)
|
||||
}
|
||||
|
||||
// small io.Writer utility to determine if executing the template wrote to the underlying response writer.
|
||||
type writeRecorder struct {
|
||||
wrote bool
|
||||
|
||||
Reference in New Issue
Block a user