diff --git a/controller/controller.go b/controller/controller.go
index 6048375..6b1baec 100644
--- a/controller/controller.go
+++ b/controller/controller.go
@@ -156,6 +156,11 @@ func (c *Controller) Redirect(ctx echo.Context, route string, routeParams ...int
return ctx.Redirect(http.StatusFound, ctx.Echo().Reverse(route, routeParams))
}
+func (c *Controller) Fail(ctx echo.Context, err error, log string) error {
+ ctx.Logger().Errorf("%s: %v", log, err)
+ return echo.NewHTTPError(500)
+}
+
// SetValidationErrorMessages sets error flash messages for validation failures of a given struct
// and attempts to provide more user-friendly wording.
// The error should result from the validator module and the data should be the struct that failed
diff --git a/routes/contact.go b/routes/contact.go
index 8817db7..faf409a 100644
--- a/routes/contact.go
+++ b/routes/contact.go
@@ -34,29 +34,21 @@ func (c *Contact) Get(ctx echo.Context) error {
}
func (c *Contact) Post(ctx echo.Context) error {
- //fail := func(message string, err error) error {
- // ctx.Logger().Errorf("%s: %v", message, err)
- // msg.Danger(ctx, "An error occurred. Please try again.")
- // return c.Get(ctx)
- //}
-
- // TODO: Error handling w/ HTMX support
-
// Parse the form values
var form ContactForm
if err := ctx.Bind(&form); err != nil {
- ctx.Logger().Error(err)
+ return c.Fail(ctx, err, "unable to bind form")
}
if err := form.Submission.Process(ctx, form); err != nil {
- // TOOD
+ return c.Fail(ctx, err, "unable to process form submission")
}
ctx.Set(context.FormKey, form)
if !form.Submission.HasErrors() {
if err := c.Container.Mail.Send(ctx, form.Email, "Hello!"); err != nil {
- ctx.Logger().Error(err)
+ return c.Fail(ctx, err, "unable to send email")
}
}
diff --git a/routes/error.go b/routes/error.go
index a428f88..db037b5 100644
--- a/routes/error.go
+++ b/routes/error.go
@@ -33,6 +33,7 @@ func (e *Error) Get(err error, c echo.Context) {
p.Title = http.StatusText(code)
p.Name = "error"
p.StatusCode = code
+ p.HTMX.Request.Enabled = false
if err = e.RenderPage(c, p); err != nil {
c.Logger().Error(err)
diff --git a/templates/components/core.gohtml b/templates/components/core.gohtml
index 4d6aeeb..acdb815 100644
--- a/templates/components/core.gohtml
+++ b/templates/components/core.gohtml
@@ -24,9 +24,19 @@
{{define "footer"}}
{{- if .CSRF}}
{{end}}
+
{{end}}
\ No newline at end of file
diff --git a/templates/layouts/main.gohtml b/templates/layouts/main.gohtml
index 22a9b61..637cb1d 100644
--- a/templates/layouts/main.gohtml
+++ b/templates/layouts/main.gohtml
@@ -39,6 +39,6 @@
- {{template "footer"}}
+ {{template "footer" .}}