Skip to content

Commit

Permalink
Fix redundant echo/http error wrapping.
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Jul 9, 2022
1 parent 4a6e041 commit 68da86a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions cmd/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions cmd/tx.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"net/http"
"net/textproto"

Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit 68da86a

Please sign in to comment.