Skip to content

Commit c66329d

Browse files
authored
UX: Show an obvious timeout error instead of a generic one (#216)
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
1 parent 53cdbc8 commit c66329d

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

app/services/discourse_translator/base.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ def self.access_token
7878
end
7979

8080
def self.save_translation(translatable, target_locale_sym = I18n.locale)
81-
translation = yield
81+
begin
82+
translation = yield
83+
rescue Timeout::Error
84+
raise TranslatorError.new(I18n.t("translator.api_timeout"))
85+
end
8286
translatable.set_translation(target_locale_sym, translation)
8387
translation
8488
end

config/locales/server.en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ en:
2727
not_supported: "This language is not supported by the translator."
2828
too_long: "This post is too long to be translated by the translator."
2929
not_available: "The translator service is currently not available."
30+
api_timeout: "The translator service took too long to respond. Please try again later."
3031
amazon:
3132
invalid_credentials: "The provided credentials for AWS translate are invalid."
3233

0 commit comments

Comments
 (0)