From 80845c9cf05fb4a16c43430283cd4cf25e99bb5e Mon Sep 17 00:00:00 2001 From: Daniel Nitsikopoulos Date: Sat, 24 Feb 2024 16:30:51 +1100 Subject: [PATCH] Fix status code --- slices/micropub/actions/posts/handle.rb | 9 +++++---- slices/micropub/commands/posts/update.rb | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/slices/micropub/actions/posts/handle.rb b/slices/micropub/actions/posts/handle.rb index 22d495f..f1b28f2 100644 --- a/slices/micropub/actions/posts/handle.rb +++ b/slices/micropub/actions/posts/handle.rb @@ -22,12 +22,13 @@ module Micropub if action_type case resolve_command(req: req, action_type: action_type) in Success[command] - command.call(params: req.params.to_h) - res.status = 200 + if command.call(params: req.params.to_h).success? + res.status = 200 + else + halt 400 + end in Failure[:not_permitted] halt 401 - in Failure[:invalid_request] - halt 400 end end diff --git a/slices/micropub/commands/posts/update.rb b/slices/micropub/commands/posts/update.rb index 252be65..aaaa7d8 100644 --- a/slices/micropub/commands/posts/update.rb +++ b/slices/micropub/commands/posts/update.rb @@ -13,7 +13,7 @@ module Micropub post = post_repo.fetch!(slug) if params.key? :replace - return Failure(:invalid_request) 400 unless params[:replace].is_a?(Hash) + return Failure(:invalid_request) unless params[:replace].is_a?(Hash) content = params[:replace].delete(:content) content = content.is_a?(Array) ? content.first : content