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

This commit is contained in:
Dan Ungureanu 2020-04-25 11:47:22 +03:00
parent 3de901e38d
commit 0ae504aece
No known key found for this signature in database
GPG Key ID: 0AA2A00D6ACC8B84

View File

@ -51,7 +51,13 @@ class DraftController < ApplicationController
json = success_json.merge(draft_sequence: sequence) 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 # 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 # we need to catch action edit and action editSharedDraft
if data["postId"].present? && data["originalText"].present? && data["action"].to_s.start_with?("edit") if data["postId"].present? && data["originalText"].present? && data["action"].to_s.start_with?("edit")