Skip to content

Commit

Permalink
UX: Show an obvious timeout error instead of a generic one (#216)
Browse files Browse the repository at this point in the history
There are times when using the DiscourseAi translator that we will face a Timeout::Error due to FinalDestination resolver. This will result in a generic error surfaced

This commit makes it obvious that the user can try again
  • Loading branch information
nattsw authored Feb 18, 2025
1 parent 53cdbc8 commit c66329d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/services/discourse_translator/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ def self.access_token
end

def self.save_translation(translatable, target_locale_sym = I18n.locale)
translation = yield
begin
translation = yield
rescue Timeout::Error
raise TranslatorError.new(I18n.t("translator.api_timeout"))
end
translatable.set_translation(target_locale_sym, translation)
translation
end
Expand Down
1 change: 1 addition & 0 deletions config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ en:
not_supported: "This language is not supported by the translator."
too_long: "This post is too long to be translated by the translator."
not_available: "The translator service is currently not available."
api_timeout: "The translator service took too long to respond. Please try again later."
amazon:
invalid_credentials: "The provided credentials for AWS translate are invalid."

Expand Down

0 comments on commit c66329d

Please sign in to comment.