~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.
82fce78d
—
pyros2097 5 years ago
handle panics again
router.go
CHANGED
|
@@ -740,7 +740,17 @@ var AppRouter = &Router{
|
|
|
740
740
|
Text("This is the default 404 - Not Found Route handler"),
|
|
741
741
|
),
|
|
742
742
|
Row(
|
|
743
|
-
Text("
|
|
743
|
+
Text("use AppRouter.NotFound = func(c *RenderContext) UI {} to override it"),
|
|
744
|
+
),
|
|
745
|
+
)
|
|
746
|
+
},
|
|
747
|
+
Error: func(c *RenderContext) UI {
|
|
748
|
+
return Col(
|
|
749
|
+
Row(
|
|
750
|
+
Text("This is the default 500 - Internal Server Error Route handler"),
|
|
751
|
+
),
|
|
752
|
+
Row(
|
|
753
|
+
Text("use AppRouter.Error = func(c *RenderContext) UI {} to override it"),
|
|
744
754
|
),
|
|
745
755
|
)
|
|
746
756
|
},
|
|
@@ -854,9 +864,9 @@ func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|
|
854
864
|
// Handle errors
|
|
855
865
|
defer func() {
|
|
856
866
|
if rcv := recover(); rcv != nil {
|
|
857
|
-
writePage(r.Error(NewRenderContext()), w)
|
|
858
867
|
w.Header().Set("Content-Type", "text/html")
|
|
859
868
|
w.WriteHeader(http.StatusInternalServerError)
|
|
869
|
+
writePage(r.Error(NewRenderContext()), w)
|
|
860
870
|
}
|
|
861
871
|
}()
|
|
862
872
|
|
|
@@ -867,9 +877,9 @@ func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|
|
867
877
|
if handle, _, tsr := root.getValue(path, r.getParams); handle != nil {
|
|
868
878
|
println("route: " + req.URL.Path)
|
|
869
879
|
if render, ok := handle.(RenderFunc); ok {
|
|
870
|
-
writePage(render(NewRenderContext()), w)
|
|
871
880
|
w.Header().Set("Content-Type", "text/html")
|
|
872
881
|
w.WriteHeader(http.StatusOK)
|
|
882
|
+
writePage(render(NewRenderContext()), w)
|
|
873
883
|
return
|
|
874
884
|
} else {
|
|
875
885
|
handle.(func(w http.ResponseWriter, r *http.Request))(w, req)
|
|
@@ -897,7 +907,7 @@ func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|
|
897
907
|
}
|
|
898
908
|
|
|
899
909
|
// Handle 404
|
|
900
|
-
writePage(r.NotFound(NewRenderContext()), w)
|
|
901
910
|
w.Header().Set("Content-Type", "text/html")
|
|
902
911
|
w.WriteHeader(http.StatusNotFound)
|
|
912
|
+
writePage(r.NotFound(NewRenderContext()), w)
|
|
903
913
|
}
|