fix: nil pointer access (#504)

Reviewed-on: https://codeberg.org/Codeberg/pages-server/pulls/504
Co-authored-by: crapStone <me@crapstone.dev>
Co-committed-by: crapStone <me@crapstone.dev>
This commit is contained in:
crapStone 2025-07-03 22:52:58 +02:00 committed by crapStone
parent 16ae6eacfe
commit 838a5bda92
4 changed files with 56 additions and 21 deletions

View file

@ -64,8 +64,12 @@ func handleRaw(log zerolog.Logger, ctx *context.Context, giteaClient *gitea.Clie
log.Trace().Msg("tryUpstream: serve raw domain with default branch")
tryUpstream(log, ctx, giteaClient, mainDomainSuffix, trimmedHost, targetOpt, canonicalDomainCache, redirectsCache)
} else {
html.ReturnErrorPage(ctx,
fmt.Sprintf("raw domain could not find repo <code>%s/%s</code> or repo is empty", targetOpt.TargetOwner, targetOpt.TargetRepo),
http.StatusNotFound)
if targetOpt == nil {
html.ReturnErrorPage(ctx, "raw domain could not find repo", http.StatusNotFound)
} else {
html.ReturnErrorPage(ctx,
fmt.Sprintf("raw domain could not find repo <code>%s/%s</code> or repo is empty", targetOpt.TargetOwner, targetOpt.TargetRepo),
http.StatusNotFound)
}
}
}