Do some better error handling in template rendering
This commit is contained in:
parent
e7e420cd47
commit
2ba0a0024e
2 changed files with 13 additions and 3 deletions
|
|
@ -37,7 +37,7 @@ func view(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
context := map[string]any{"note": note, "urlEdit": urlEdit}
|
||||
context := templ.Ctx{"note": note, "urlEdit": urlEdit}
|
||||
note.Render()
|
||||
err = templ.RenderTemplate(w, "view.tmpl.html", context)
|
||||
if err != nil {
|
||||
|
|
@ -55,7 +55,7 @@ func edit(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
urlSave := myurls.Reverse("save", urls.Repl{"note": title})
|
||||
context := map[string]any{"note": note, "urlSave": urlSave}
|
||||
context := templ.Ctx{"note": note, "urlSave": urlSave}
|
||||
err = templ.RenderTemplate(w, "edit.tmpl.html", context)
|
||||
if err != nil {
|
||||
log.Print(err.Error())
|
||||
|
|
@ -89,7 +89,7 @@ func list(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
err = templ.RenderTemplate(w, "list.tmpl.html", map[string]any{"titles": titles})
|
||||
err = templ.RenderTemplate(w, "list.tmpl.html", templ.Ctx{"titles": titles})
|
||||
if err != nil {
|
||||
log.Print(err.Error())
|
||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue