feat: return distinct 'draft' error for draft post detail requests

Previously the API returned 'not_found' for both missing and draft
posts. Now draft posts return a specific 'draft' error code so API
consumers can distinguish between the two cases and show an
appropriate message.
This commit is contained in:
2026-06-26 20:44:42 +02:00
parent 781707a3fd
commit 5cc3a1aabe
2 changed files with 4 additions and 3 deletions
+2 -1
View File
@@ -28,7 +28,8 @@ module Volumen
app.get "/api/volumen/posts/:slug" do app.get "/api/volumen/posts/:slug" do
post = store.find(params["slug"], lang: params["lang"]) post = store.find(params["slug"], lang: params["lang"])
halt(404, json("error" => "not_found")) if post.nil? || post.draft? halt(404, json("error" => "not_found")) if post.nil?
halt(404, json("error" => "draft")) if post.draft?
json(post.detail) json(post.detail)
end end
+2 -2
View File
@@ -104,10 +104,10 @@ class ServerTest < Minitest::Test
assert_includes body, "<language>en</language>" assert_includes body, "<language>en</language>"
end end
def test_draft_post_detail_is_not_found def test_draft_post_detail_returns_draft_error
get "/api/volumen/posts/draft" get "/api/volumen/posts/draft"
assert_equal 404, last_response.status assert_equal 404, last_response.status
assert_equal "not_found", JSON.parse(last_response.body)["error"] assert_equal "draft", JSON.parse(last_response.body)["error"]
end end
def test_sitemap_endpoint def test_sitemap_endpoint