mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 05:01:14 +08:00
FIX: prevents creating post from impacting the app (#28518)
Create a topic can fail in many different ways and we don't want this to impact the rest of the application, the call will now be wrapped in a begin/rescue block and log an error if it fails.
This commit is contained in:
@ -60,14 +60,19 @@ DiscourseAutomation::Scriptable.add(DiscourseAutomation::Scripts::TOPIC) do
|
||||
end
|
||||
|
||||
tags = fields.dig("tags", "value") || []
|
||||
new_post =
|
||||
PostCreator.new(
|
||||
creator,
|
||||
raw: topic_raw,
|
||||
title: title,
|
||||
category: category.id,
|
||||
tags: tags,
|
||||
).create!
|
||||
begin
|
||||
new_post =
|
||||
PostCreator.new(
|
||||
creator,
|
||||
raw: topic_raw,
|
||||
title: title,
|
||||
category: category.id,
|
||||
tags: tags,
|
||||
).create!
|
||||
rescue StandardError => e
|
||||
Rails.logger.warn "[discourse-automation] couldn't create post: #{e.message}"
|
||||
next
|
||||
end
|
||||
|
||||
if context["kind"] == DiscourseAutomation::Triggers::USER_UPDATED && new_post.persisted?
|
||||
user.user_custom_fields.create(name: automation.name, value: "true")
|
||||
|
Reference in New Issue
Block a user