add missing error handling in article creation

Signed-off-by: Tobias Erbshäußer <tobias@tesoft.dev>
This commit is contained in:
2026-05-24 09:22:29 +02:00
parent d80c218945
commit a2e840f8fb
+6 -2
View File
@@ -203,8 +203,6 @@ func (h *ApiHandler) ServeBlogPut(writer http.ResponseWriter, request *http.Requ
_ = file.Close() _ = file.Close()
}() }()
log.Println("creating new blog article ...")
id, commit, err := h.db.CreateBlogArticle() id, commit, err := h.db.CreateBlogArticle()
if err != nil { if err != nil {
WriteError(writer, http.StatusInternalServerError, "failed to write database", err) WriteError(writer, http.StatusInternalServerError, "failed to write database", err)
@@ -219,6 +217,12 @@ func (h *ApiHandler) ServeBlogPut(writer http.ResponseWriter, request *http.Requ
} }
err = commit(article) err = commit(article)
if err != nil {
WriteError(writer, http.StatusInternalServerError, "failed to write database", err)
return
}
log.Printf("created new blog article '%s'", article.Title)
WriteResponse(writer, http.StatusOK, map[string]interface{}{ WriteResponse(writer, http.StatusOK, map[string]interface{}{
"id": id, "id": id,