Skip to content

Commit

Permalink
Fix incorrect 'get subscriber' calls
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Feb 15, 2021
1 parent e90fb1d commit 97b78aa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
5 changes: 2 additions & 3 deletions cmd/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,14 @@ func handleViewCampaignMessage(c echo.Context) error {
}

// Get the subscriber.
var sub models.Subscriber
if err := app.queries.GetSubscriber.Get(&sub, 0, subUUID); err != nil {
sub, err := getSubscriber(0, subUUID, "", app)
if err != nil {
if err == sql.ErrNoRows {
return c.Render(http.StatusNotFound, tplMessage,
makeMsgTpl(app.i18n.T("public.notFoundTitle"), "",
app.i18n.T("public.errorFetchingEmail")))
}

app.log.Printf("error fetching campaign subscriber: %v", err)
return c.Render(http.StatusInternalServerError, tplMessage,
makeMsgTpl(app.i18n.T("public.errorTitle"), "",
app.i18n.Ts("public.errorFetchingCampaign")))
Expand Down
9 changes: 2 additions & 7 deletions cmd/subscribers.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,27 +338,22 @@ func handleSubscriberSendOptin(c echo.Context) error {
var (
app = c.Get("app").(*App)
id, _ = strconv.Atoi(c.Param("id"))
out models.Subscribers
)

if id < 1 {
return echo.NewHTTPError(http.StatusBadRequest, app.i18n.T("globals.messages.invalidID"))
}

// Fetch the subscriber.
err := app.queries.GetSubscriber.Select(&out, id, nil)
out, err := getSubscriber(id, "", "", app)
if err != nil {
app.log.Printf("error fetching subscriber: %v", err)
return echo.NewHTTPError(http.StatusInternalServerError,
app.i18n.Ts("globals.messages.errorFetching",
"name", "{globals.terms.subscribers}", "error", pqErrMsg(err)))
}
if len(out) == 0 {
return echo.NewHTTPError(http.StatusBadRequest,
app.i18n.Ts("globals.messages.notFound", "name", "{globals.terms.subscriber}"))
}

if _, err := sendOptinConfirmation(out[0], nil, app); err != nil {
if _, err := sendOptinConfirmation(out, nil, app); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError,
app.i18n.T("subscribers.errorSendingOptin"))
}
Expand Down

0 comments on commit 97b78aa

Please sign in to comment.