add missing error handling in article creation
Signed-off-by: Tobias Erbshäußer <tobias@tesoft.dev>
This commit is contained in:
+6
-2
@@ -203,8 +203,6 @@ func (h *ApiHandler) ServeBlogPut(writer http.ResponseWriter, request *http.Requ
|
||||
_ = file.Close()
|
||||
}()
|
||||
|
||||
log.Println("creating new blog article ...")
|
||||
|
||||
id, commit, err := h.db.CreateBlogArticle()
|
||||
if err != nil {
|
||||
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)
|
||||
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{}{
|
||||
"id": id,
|
||||
|
||||
Reference in New Issue
Block a user