Fix error messages for reacting & listing errors

This commit is contained in:
Karina Kwiatek 2022-06-13 11:48:49 +02:00 committed by Karina Kwiatek
parent 0db51536c5
commit c8b6689a61
2 changed files with 19 additions and 7 deletions

View File

@ -8,7 +8,7 @@ class Ajax::SmileController < AjaxController
current_user.smile answer current_user.smile answer
rescue Errors::Base => e rescue Errors::Base => e
@response[:status] = e.code @response[:status] = e.code
@response[:message] = e.locale_tag @response[:message] = I18n.t(e.locale_tag)
return return
rescue => e rescue => e
Sentry.capture_exception(e) Sentry.capture_exception(e)
@ -50,7 +50,7 @@ class Ajax::SmileController < AjaxController
current_user.smile_comment comment current_user.smile_comment comment
rescue Errors::Base => e rescue Errors::Base => e
@response[:status] = e.code @response[:status] = e.code
@response[:message] = e.locale_tag @response[:message] = I18n.t(e.locale_tag)
return return
rescue => e rescue => e
Sentry.capture_exception(e) Sentry.capture_exception(e)

View File

@ -8,8 +8,12 @@ module Errors
@code ||= self.class.name.sub('Errors::', '').underscore @code ||= self.class.name.sub('Errors::', '').underscore
end end
def locale_code
code
end
def locale_tag def locale_tag
@locale_tag ||= "errors.#{code}" @locale_tag ||= "errors.#{locale_code}"
end end
end end
@ -81,19 +85,27 @@ module Errors
end end
class ReactingSelfBlockedOther < SelfBlockedOther class ReactingSelfBlockedOther < SelfBlockedOther
@locale_tag = "errors.self_blocked_other" def locale_code
"self_blocked_other"
end
end end
class ReactingOtherBlockedSelf < OtherBlockedSelf class ReactingOtherBlockedSelf < OtherBlockedSelf
@locale_tag = "errors.other_blocked_self" def locale_code
"other_blocked_self"
end
end end
class ListingSelfBlockedOther < SelfBlockedOther class ListingSelfBlockedOther < SelfBlockedOther
@locale_tag = "errors.self_blocked_other" def locale_code
"self_blocked_other"
end
end end
class ListingOtherBlockedSelf < OtherBlockedSelf class ListingOtherBlockedSelf < OtherBlockedSelf
@locale_tag = "errors.other_blocked_self" def locale_code
"other_blocked_self"
end
end end
# endregion # endregion
end end