From 68da86aadcfb59ddbb97861322d41d47139ebb7f Mon Sep 17 00:00:00 2001 From: Kailash Nadh Date: Sat, 2 Jul 2022 16:07:29 +0530 Subject: [PATCH] Fix redundant echo/http error wrapping. --- cmd/templates.go | 4 ++-- cmd/tx.go | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/templates.go b/cmd/templates.go index bed1690f..4f2c065e 100644 --- a/cmd/templates.go +++ b/cmd/templates.go @@ -126,7 +126,7 @@ func handleCreateTemplate(c echo.Context) error { } if err := validateTemplate(o, app); err != nil { - return echo.NewHTTPError(http.StatusBadRequest, err.Error()) + return err } // Subject is only relevant for fixed tx templates. For campaigns, @@ -172,7 +172,7 @@ func handleUpdateTemplate(c echo.Context) error { } if err := validateTemplate(o, app); err != nil { - return echo.NewHTTPError(http.StatusBadRequest, err.Error()) + return err } // Subject is only relevant for fixed tx templates. For campaigns, diff --git a/cmd/tx.go b/cmd/tx.go index 5855a042..893fb419 100644 --- a/cmd/tx.go +++ b/cmd/tx.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "net/http" "net/textproto" @@ -30,7 +31,8 @@ func handleSendTxMessage(c echo.Context) error { // Get the cached tx template. tpl, err := app.manager.GetTpl(m.TemplateID) if err != nil { - return err + return echo.NewHTTPError(http.StatusBadRequest, + app.i18n.Ts("globals.messages.notFound", "name", fmt.Sprintf("template %d", m.TemplateID))) } // Get the subscriber. @@ -41,7 +43,8 @@ func handleSendTxMessage(c echo.Context) error { // Render the message. if err := m.Render(sub, tpl); err != nil { - return err + return echo.NewHTTPError(http.StatusBadRequest, + app.i18n.Ts("globals.messages.errorFetching", "name")) } // Prepare the final message.