Skip to content

Commit e67fbd2

Browse files
committed
fix(demos): handle errors when rendering toast components' HTML and CSS
1 parent 4b0b1dc commit e67fbd2

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

demos/handlers/gohtml-multiple.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ func HandleGoHtmlMultiple(w http.ResponseWriter, r *http.Request) {
1818
toastHTMLGenerator := goaster.NewHTMLGenerator()
1919

2020
// Render the needed CSS for toast component as template.HTML
21-
toastCSS, _ := toastHTMLGenerator.GoasterCSSToGoHTML()
21+
toastCSS, err := toastHTMLGenerator.GoasterCSSToGoHTML()
22+
if err != nil {
23+
http.Error(w, "failed to render toast CSS", http.StatusInternalServerError)
24+
log.Printf("failed to render toast CSS: %v", err)
25+
return
26+
}
2227

2328
// Push messages
2429
toaster.PushDefault("Default Toast")
@@ -29,9 +34,19 @@ func HandleGoHtmlMultiple(w http.ResponseWriter, r *http.Request) {
2934

3035
// Render the toast component into a template.HTML
3136
toastHtml, err := toastHTMLGenerator.DisplayAll(toaster)
37+
if err != nil {
38+
http.Error(w, "failed to render toast HTML", http.StatusInternalServerError)
39+
log.Printf("failed to render toast HTML: %v", err)
40+
return
41+
}
3242

3343
// Render the needed JS for toast component as template.HTML
34-
toastJS, _ := toastHTMLGenerator.GoasterJSToGoHTML(toaster, nil)
44+
toastJS, err := toastHTMLGenerator.GoasterJSToGoHTML(toaster, nil)
45+
if err != nil {
46+
http.Error(w, "failed to render toast JS", http.StatusInternalServerError)
47+
log.Printf("failed to render toast JS: %v", err)
48+
return
49+
}
3550

3651
data := types.PageData{
3752
Toast: types.ToastComponent{

demos/handlers/gohtml-single.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ func HandleGoHtmlSingle(w http.ResponseWriter, r *http.Request) {
1919
toastHTMLGenerator := goaster.NewHTMLGenerator()
2020

2121
// Render the needed CSS for toast component as template.HTML
22-
toastCSS, _ := toastHTMLGenerator.GoasterCSSToGoHTML()
22+
toastCSS, err := toastHTMLGenerator.GoasterCSSToGoHTML()
23+
if err != nil {
24+
http.Error(w, "failed to render toast CSS", http.StatusInternalServerError)
25+
log.Printf("failed to render toast CSS: %v", err)
26+
return
27+
}
2328

2429
// Render the toast component into a template.HTML
2530
c := toaster.Success("Success Toast")
@@ -32,7 +37,12 @@ func HandleGoHtmlSingle(w http.ResponseWriter, r *http.Request) {
3237
}
3338

3439
// Render the needed JS for toast component as template.HTML
35-
toastJS, _ := toastHTMLGenerator.GoasterJSToGoHTML(toaster, nil)
40+
toastJS, err := toastHTMLGenerator.GoasterJSToGoHTML(toaster, nil)
41+
if err != nil {
42+
http.Error(w, "failed to render toast JS", http.StatusInternalServerError)
43+
log.Printf("failed to render toast JS: %v", err)
44+
return
45+
}
3646

3747
data := types.PageData{
3848
Toast: types.ToastComponent{

0 commit comments

Comments
 (0)