FIX: Raise a 4xx error instead of a 5xx if draft data is invalid

FIX: Raise a 4xx error instead of a 5xx if draft data is invalid

diff --git a/app/controllers/draft_controller.rb b/app/controllers/draft_controller.rb
index d3cc2b7..22cedd3 100644
--- a/app/controllers/draft_controller.rb
+++ b/app/controllers/draft_controller.rb
@@ -51,7 +51,13 @@ class DraftController < ApplicationController
 
     json = success_json.merge(draft_sequence: sequence)
 
-    if data = JSON::parse(params[:data])
+    begin
+      data = JSON::parse(params[:data])
+    rescue JSON::ParserError
+      raise Discourse::InvalidParameters.new(:data)
+    end
+
+    if data.present?
       # this is a bit of a kludge we need to remove (all the parsing) too many special cases here
       # we need to catch action edit and action editSharedDraft
       if data["postId"].present? && data["originalText"].present? && data["action"].to_s.start_with?("edit")

GitHub sha: 0ae504ae

1 Like