From 5cc3a1aabe2e924799bdd1a27737a2cd9246f39b Mon Sep 17 00:00:00 2001 From: Petr Date: Fri, 26 Jun 2026 20:44:42 +0200 Subject: [PATCH] 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. --- lib/volumen/api_routes.rb | 3 ++- test/server_test.rb | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/volumen/api_routes.rb b/lib/volumen/api_routes.rb index b2a3091..1576439 100644 --- a/lib/volumen/api_routes.rb +++ b/lib/volumen/api_routes.rb @@ -28,7 +28,8 @@ module Volumen app.get "/api/volumen/posts/:slug" do 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) end diff --git a/test/server_test.rb b/test/server_test.rb index e0dcf40..25a2fde 100644 --- a/test/server_test.rb +++ b/test/server_test.rb @@ -104,10 +104,10 @@ class ServerTest < Minitest::Test assert_includes body, "en" end - def test_draft_post_detail_is_not_found + def test_draft_post_detail_returns_draft_error get "/api/volumen/posts/draft" 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 def test_sitemap_endpoint