forked from jason/cpolis
Show error messages in UI if something goes wrong
This commit is contained in:
@@ -87,6 +87,15 @@ func SubmitArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
AutoGenerated: false,
|
||||
}
|
||||
|
||||
if len(article.Title) == 0 {
|
||||
http.Error(w, "Bitte den Titel eingeben.", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if len(article.Description) == 0 {
|
||||
http.Error(w, "Bitte die Beschreibung eingeben.", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
article.ID, err = db.AddArticle(article)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
@@ -94,8 +103,14 @@ func SubmitArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
content := []byte(r.PostFormValue("article-content"))
|
||||
if len(content) == 0 {
|
||||
http.Error(w, "Bitte den Artikel eingeben.", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
articleAbsName := fmt.Sprint(c.ArticleDir, "/", article.ID, ".md")
|
||||
if err = os.WriteFile(articleAbsName, []byte(r.PostFormValue("article-content")), 0644); err != nil {
|
||||
if err = os.WriteFile(articleAbsName, content, 0644); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@@ -152,8 +167,22 @@ func ResubmitArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
}
|
||||
|
||||
title := r.PostFormValue("article-title")
|
||||
if len(title) == 0 {
|
||||
http.Error(w, "Bitte den Titel eingeben.", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
description := r.PostFormValue("article-description")
|
||||
if len(description) == 0 {
|
||||
http.Error(w, "Bitte die Beschreibung eingeben.", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
content := r.PostFormValue("article-content")
|
||||
if len(content) == 0 {
|
||||
http.Error(w, "Bitte den Artikel eingeben.", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
link := fmt.Sprint(c.ArticleDir, "/", id, ".md")
|
||||
if err = os.WriteFile(link, []byte(content), 0644); err != nil {
|
||||
@@ -509,6 +538,10 @@ func UploadArticleImage(c *b.Config, s *b.CookieStore) http.HandlerFunc {
|
||||
|
||||
filename, err := b.SaveImage(c, file)
|
||||
if err != nil {
|
||||
if err == b.ErrUnsupportedFormat {
|
||||
http.Error(w, "Das Dateiformat wird nicht unterstützt.", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
Reference in New Issue
Block a user