Avoid a nil exception on error redirect

pull/12/head
Noah 2022-10-20 21:07:21 -07:00
parent 47f898561c
commit f1e12f344e
1 changed files with 14 additions and 2 deletions

View File

@ -233,11 +233,23 @@ func NewPost() http.HandlerFunc {
// A message OR a photo is required.
if forum.PermitPhotos && message == "" && commentPhoto == nil {
session.FlashError(w, r, "A message OR photo is required for this post.")
templates.Redirect(w, fmt.Sprintf("/forum/thread/%d", thread.ID))
if thread != nil {
templates.Redirect(w, fmt.Sprintf("/forum/thread/%d", thread.ID))
} else if forum != nil {
templates.Redirect(w, fmt.Sprintf("/f/%s", forum.Fragment))
} else {
templates.Redirect(w, "/forum")
}
return
} else if !forum.PermitPhotos && message == "" {
session.FlashError(w, r, "A message is required for this post.")
templates.Redirect(w, fmt.Sprintf("/forum/thread/%d", thread.ID))
if thread != nil {
templates.Redirect(w, fmt.Sprintf("/forum/thread/%d", thread.ID))
} else if forum != nil {
templates.Redirect(w, fmt.Sprintf("/f/%s", forum.Fragment))
} else {
templates.Redirect(w, "/forum")
}
return
}