fix(short-url): redirect to main page if not found (#97347)

This commit is contained in:
Jean-Philippe Quéméner
2024-12-03 16:32:53 +01:00
committed by GitHub
parent 802b96c6f7
commit 5bf0872d14
2 changed files with 136 additions and 2 deletions
+6 -2
View File
@@ -46,12 +46,16 @@ func (hs *HTTPServer) redirectFromShortURL(c *contextmodel.ReqContext) {
shortURL, err := hs.ShortURLService.GetShortURLByUID(c.Req.Context(), c.SignedInUser, shortURLUID)
if err != nil {
// If we didn't get the URL for whatever reason, we redirect to the
// main page, otherwise we get into an endless loops of redirects, as
// we would try to redirect again.
if shorturls.ErrShortURLNotFound.Is(err) {
hs.log.Debug("Not redirecting short URL since not found")
hs.log.Debug("Not redirecting short URL since not found", "uid", shortURLUID)
c.Redirect(hs.Cfg.AppURL, 308)
return
}
hs.log.Error("Short URL redirection error", "err", err)
c.Redirect(hs.Cfg.AppURL, 307)
return
}