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

@ -24,11 +24,13 @@
(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")
(if-let [slug (not-empty slug)]
(let [{success :success :as res} (snippets.use-cases.edit/edit-snippet slug body)] (let [{success :success :as res} (snippets.use-cases.edit/edit-snippet slug body)]
(cond (cond
success {:status 200, :body "snippet updated"} success {:status 200, :body "snippet updated"}
(= (:reason res) :invalid-patch) {:status 400, :body "invalid patch"} (= (:reason res) :invalid-patch) {:status 400, :body "invalid patch"}
:else {:status 500, :body "internal server error"})))) :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")]