refac: article title rules are the same in the API request and the domain; an invalid title returns 400 instead of 500

This commit is contained in:
fsylvain committed 2026-09-23 20:04:09 +02:00
1 parent ff8cd5f0ec
commit 4278d96882
9 files changed
+456 -7

No files matched your search

+5 -1
View File
@@ -23,7 +23,7 @@ type Handler struct {
}
type PostArticle struct {
Title string `json:"title" validate:"required,min=3,max=50"`
Title string `json:"title" validate:"required,min=3,max=200"`
Body string `json:"body" validate:"required,max=10000"`
}
@@ -81,6 +81,10 @@ func (h *Handler) PostArticle(w http.ResponseWriter, r *http.Request) {
Body: localArticle.Body,
})
if err != nil {
if errors.Is(err, domain.ErrInvalidTitle) {
http.Error(w, apperr.ArticleTitleErrorMessage, http.StatusBadRequest)
return
}
http.Error(w, "Failed to create article", http.StatusInternalServerError)
return
}