Show the reason the topic couldn't be split rather than a generic error.
This commit is contained in:
parent
e564614b70
commit
21185617b0
|
@ -54,9 +54,19 @@ export default Discourse.ObjectController.extend(Discourse.SelectedPostsCount, D
|
|||
self.send('closeModal');
|
||||
self.get('topicController').send('toggleMultiSelect');
|
||||
Em.run.next(function() { Discourse.URL.routeTo(result.url); });
|
||||
}, function() {
|
||||
}).catch(function(xhr) {
|
||||
|
||||
var error = I18n.t('topic.split_topic.error');
|
||||
|
||||
if (xhr) {
|
||||
var json = xhr.responseJSON;
|
||||
if (json && json.errors) {
|
||||
error = json.errors[0];
|
||||
}
|
||||
}
|
||||
|
||||
// Error moving posts
|
||||
self.flash(I18n.t('topic.split_topic.error'));
|
||||
self.flash(error);
|
||||
self.set('saving', false);
|
||||
});
|
||||
return false;
|
||||
|
|
|
@ -275,6 +275,8 @@ class TopicsController < ApplicationController
|
|||
|
||||
dest_topic = move_posts_to_destination(topic)
|
||||
render_topic_changes(dest_topic)
|
||||
rescue ActiveRecord::RecordInvalid => ex
|
||||
render_json_error(ex)
|
||||
end
|
||||
|
||||
def change_post_owners
|
||||
|
|
|
@ -5,6 +5,9 @@ module JsonError
|
|||
# If we're passed a string, assume that is the error message
|
||||
return {errors: [obj]} if obj.is_a?(String)
|
||||
|
||||
# If it's an AR exception target the record
|
||||
obj = obj.record if obj.is_a?(ActiveRecord::RecordInvalid)
|
||||
|
||||
# If it looks like an activerecord object, extract its messages
|
||||
return {errors: obj.errors.full_messages } if obj.respond_to?(:errors) && obj.errors.present?
|
||||
|
||||
|
|
Loading…
Reference in New Issue