~repos /gromer
git clone https://pyrossh.dev/repos/gromer.git
gromer is a framework and cli to build multipage web apps in golang using htmx and alpinejs.
779285ce
—
pyros2097 5 years ago
fix vars bug
- attributes.go +2 -0
- router.go +17 -3
attributes.go
CHANGED
|
@@ -67,6 +67,8 @@ func mergeAttributes(parent *elem, uis ...interface{}) {
|
|
|
67
67
|
helmet.Author = string(c)
|
|
68
68
|
case HelmetKeywords:
|
|
69
69
|
helmet.Keywords = string(c)
|
|
70
|
+
case nil:
|
|
71
|
+
// don't add nil to elems
|
|
70
72
|
case UI:
|
|
71
73
|
elems = append(elems, c)
|
|
72
74
|
default:
|
router.go
CHANGED
|
@@ -7,6 +7,8 @@ import (
|
|
|
7
7
|
"sync"
|
|
8
8
|
"unicode"
|
|
9
9
|
"unicode/utf8"
|
|
10
|
+
|
|
11
|
+
"github.com/pyros2097/wapp/errors"
|
|
10
12
|
)
|
|
11
13
|
|
|
12
14
|
func min(a, b int) int {
|
|
@@ -729,7 +731,7 @@ type Router struct {
|
|
|
729
731
|
NotFound RenderFunc
|
|
730
732
|
|
|
731
733
|
// Configurable handler which is called when an error occurs.
|
|
732
|
-
Error
|
|
734
|
+
Error func(*RenderContext, error) UI
|
|
733
735
|
}
|
|
734
736
|
|
|
735
737
|
var AppRouter = &Router{
|
|
@@ -744,11 +746,14 @@ var AppRouter = &Router{
|
|
|
744
746
|
),
|
|
745
747
|
)
|
|
746
748
|
},
|
|
747
|
-
Error: func(c *RenderContext) UI {
|
|
749
|
+
Error: func(c *RenderContext, err error) UI {
|
|
748
750
|
return Col(
|
|
749
751
|
Row(
|
|
750
752
|
Text("This is the default 500 - Internal Server Error Route handler"),
|
|
751
753
|
),
|
|
754
|
+
Row(
|
|
755
|
+
Text("Error: "+err.Error()),
|
|
756
|
+
),
|
|
752
757
|
Row(
|
|
753
758
|
Text("use AppRouter.Error = func(c *RenderContext) UI {} to override it"),
|
|
754
759
|
),
|
|
@@ -864,9 +869,18 @@ func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|
|
864
869
|
// Handle errors
|
|
865
870
|
defer func() {
|
|
866
871
|
if rcv := recover(); rcv != nil {
|
|
872
|
+
var err error
|
|
873
|
+
switch x := rcv.(type) {
|
|
874
|
+
case string:
|
|
875
|
+
err = errors.New(x)
|
|
876
|
+
case error:
|
|
877
|
+
err = x
|
|
878
|
+
default:
|
|
879
|
+
err = errors.New("unknown panic")
|
|
880
|
+
}
|
|
867
881
|
w.Header().Set("Content-Type", "text/html")
|
|
868
882
|
w.WriteHeader(http.StatusInternalServerError)
|
|
869
|
-
writePage(r.Error(NewRenderContext()), w)
|
|
883
|
+
writePage(r.Error(NewRenderContext(), err), w)
|
|
870
884
|
}
|
|
871
885
|
}()
|
|
872
886
|
|