Move app/labor/error_message_cleaner.rb to service (#11679)
This commit is contained in:
parent
195e228307
commit
c5a29826e8
4 changed files with 17 additions and 18 deletions
|
|
@ -88,7 +88,7 @@ class ArticlesController < ApplicationController
|
|||
processed_html = parsed_markdown.finalize
|
||||
rescue StandardError => e
|
||||
@article = Article.new(body_markdown: params[:article_body])
|
||||
@article.errors[:base] << ErrorMessageCleaner.new(e.message).clean
|
||||
@article.errors[:base] << ErrorMessages::Clean.call(e.message)
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
class ErrorMessageCleaner
|
||||
attr_accessor :error_message
|
||||
|
||||
def initialize(error_message)
|
||||
@error_message = error_message
|
||||
end
|
||||
|
||||
def clean
|
||||
if error_message.include?("expected key while parsing a block mapping at line")
|
||||
"There was a problem parsing the front-matter YAML. Perhaps you need to escape a quote " \
|
||||
"or a colon or something. Email #{SiteConfig.email_addresses[:contact]} if you are having trouble."
|
||||
else
|
||||
error_message
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -427,7 +427,7 @@ class Article < ApplicationRecord
|
|||
|
||||
self.description = processed_description if description.blank?
|
||||
rescue StandardError => e
|
||||
errors[:base] << ErrorMessageCleaner.new(e.message).clean
|
||||
errors[:base] << ErrorMessages::Clean.call(e.message)
|
||||
end
|
||||
|
||||
def set_tag_list(tags)
|
||||
|
|
|
|||
15
app/services/error_messages/clean.rb
Normal file
15
app/services/error_messages/clean.rb
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
module ErrorMessages
|
||||
class Clean
|
||||
FRONTMATTER_ERROR = /expected key while parsing a block mapping at line/.freeze
|
||||
|
||||
REPLACEMENT_ERROR = "There was a problem parsing the front-matter YAML. " \
|
||||
"Perhaps you need to escape a quote or a colon or something. " \
|
||||
"Email %s if you are having trouble.".freeze
|
||||
|
||||
def self.call(error_message)
|
||||
return error_message unless error_message.match?(FRONTMATTER_ERROR)
|
||||
|
||||
format(REPLACEMENT_ERROR, SiteConfig.email_addresses[:contact])
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue