From 6262fc0847e280b793a33fa2543a393e4ad8ca99 Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Fri, 17 Jan 2025 14:53:24 +0100 Subject: [PATCH] Add status and description to 404 error Preserve "error" for backward compatibility Close #333 --- lib/app.rb | 2 +- spec/lib/app_spec.rb | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/app.rb b/lib/app.rb index 99bcd00..82328ac 100644 --- a/lib/app.rb +++ b/lib/app.rb @@ -33,7 +33,7 @@ class App < Sinatra::Base # A custom 404 page # not_found do - JSON.dump(error: 'not found') + JSON.dump(error: 'not found', status: 404, description: 'Document not found') end # diff --git a/spec/lib/app_spec.rb b/spec/lib/app_spec.rb index 090311b..ee008a6 100644 --- a/spec/lib/app_spec.rb +++ b/spec/lib/app_spec.rb @@ -102,7 +102,9 @@ def show_backtrace(response) } expect(last_response.status).to eq 404 expect(last_response.content_type).to eq 'application/json' - expect(JSON.parse(last_response.body)).to be_a Hash + expect(JSON.parse(last_response.body)).to match( + { "status" => 404, "description" => "Document not found", "error" => "not found" } + ) expect(Colore::Sidekiq::ConversionWorker).not_to have_received(:perform_async) end end