Fix broken public link redirect.

This commit is contained in:
Kailash Nadh 2022-05-05 18:05:13 +05:30
parent 5fd4d7b44b
commit b94da621d7
2 changed files with 9 additions and 7 deletions

View file

@ -353,8 +353,8 @@ func handleLinkRedirect(c echo.Context) error {
subUUID = ""
}
var url string
if err := app.core.RegisterCampaignLinkClick(linkUUID, campUUID, subUUID); err != nil {
url, err := app.core.RegisterCampaignLinkClick(linkUUID, campUUID, subUUID)
if err != nil {
e := err.(*echo.HTTPError)
return c.Render(e.Code, tplMessage, makeMsgTpl(app.i18n.T("public.errorTitle"), "", e.Error()))
}

View file

@ -329,14 +329,16 @@ func (c *Core) RegisterCampaignView(campUUID, subUUID string) error {
}
// RegisterCampaignLinkClick registers a subscriber's link click on a campaign.
func (c *Core) RegisterCampaignLinkClick(linkUUID, campUUID, subUUID string) error {
if _, err := c.q.RegisterLinkClick.Exec(linkUUID, campUUID, subUUID); err != nil {
func (c *Core) RegisterCampaignLinkClick(linkUUID, campUUID, subUUID string) (string, error) {
var url string
if err := c.q.RegisterLinkClick.Get(&url, linkUUID, campUUID, subUUID); err != nil {
if pqErr, ok := err.(*pq.Error); ok && pqErr.Column == "link_id" {
return echo.NewHTTPError(http.StatusBadRequest, c.i18n.Ts("public.invalidLink"))
return "", echo.NewHTTPError(http.StatusBadRequest, c.i18n.Ts("public.invalidLink"))
}
c.log.Printf("error registering link click: %s", err)
return echo.NewHTTPError(http.StatusInternalServerError, c.i18n.Ts("public.errorProcessingRequest"))
return "", echo.NewHTTPError(http.StatusInternalServerError, c.i18n.Ts("public.errorProcessingRequest"))
}
return nil
return url, nil
}