handle missing slug gracefully in handle-edit-snippet

This commit is contained in:
Travis Shears 2026-03-11 09:55:59 +01:00
parent 9146f2640d
commit 04520a5790
Signed by: travisshears
GPG key ID: CB9BF1910F3F7469

View file

@ -22,13 +22,15 @@
{:status 200, :body "snippet created"}) {:status 200, :body "snippet created"})
(defn handle-edit-snippet [{body :body-params params :query-params}] (defn handle-edit-snippet [{body :body-params params :query-params}]
(let [slug (get params "slug")] (let [slug (get params "slug")]
(t/log! {:level :info, :data {:body body :slug slug}} "Received request to edit snippet") (t/log! {:level :info, :data {:body body :slug slug}} "Received request to edit snippet")
(let [{success :success :as res} (snippets.use-cases.edit/edit-snippet slug body)] (if-let [slug (not-empty slug)]
(cond (let [{success :success :as res} (snippets.use-cases.edit/edit-snippet slug body)]
success {:status 200, :body "snippet updated"} (cond
(= (:reason res) :invalid-patch) {:status 400, :body "invalid patch"} success {:status 200, :body "snippet updated"}
:else {:status 500, :body "internal server error"})))) (= (:reason res) :invalid-patch) {:status 400, :body "invalid patch"}
:else {:status 500, :body "internal server error"}))
{:status 400, :body "missing slug param"})))
(defn handle-view-snippets [{params :query-params}] (defn handle-view-snippets [{params :query-params}]
(if-let [limit (get params "limit")] (if-let [limit (get params "limit")]