Redirect to homepage on bad slug
This commit is contained in:
parent
9c19484333
commit
e3257bb383
|
@ -167,14 +167,17 @@ func getBaseData(c *RequestContext) templates.BaseData {
|
|||
}
|
||||
|
||||
func FetchProjectBySlug(ctx context.Context, conn *pgxpool.Pool, slug string) (*models.Project, error) {
|
||||
if len(slug) > 0 && slug != models.HMNProjectSlug {
|
||||
subdomainProjectRow, err := db.QueryOne(ctx, conn, models.Project{}, "SELECT $columns FROM handmade_project WHERE slug = $1", slug)
|
||||
if err == nil {
|
||||
subdomainProject := subdomainProjectRow.(*models.Project)
|
||||
return subdomainProject, nil
|
||||
} else if !errors.Is(err, db.ErrNoMatchingRows) {
|
||||
return nil, oops.New(err, "failed to get projects by slug")
|
||||
} else {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
} else {
|
||||
defaultProjectRow, err := db.QueryOne(ctx, conn, models.Project{}, "SELECT $columns FROM handmade_project WHERE id = $1", models.HMNProjectID)
|
||||
if err != nil {
|
||||
if errors.Is(err, db.ErrNoMatchingRows) {
|
||||
|
@ -184,8 +187,8 @@ func FetchProjectBySlug(ctx context.Context, conn *pgxpool.Pool, slug string) (*
|
|||
}
|
||||
}
|
||||
defaultProject := defaultProjectRow.(*models.Project)
|
||||
|
||||
return defaultProject, nil
|
||||
}
|
||||
}
|
||||
|
||||
func ProjectCSS(c *RequestContext) ResponseData {
|
||||
|
@ -262,6 +265,9 @@ func LoadCommonWebsiteData(c *RequestContext) (bool, ResponseData) {
|
|||
if err != nil {
|
||||
return false, ErrorResponse(http.StatusInternalServerError, oops.New(err, "failed to fetch current project"))
|
||||
}
|
||||
if dbProject == nil {
|
||||
return false, c.Redirect(hmnurl.BuildHomepage(), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
c.CurrentProject = dbProject
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue