Skip to content

Commit 57ea2e1

Browse files
committed
Fix reporting of deepl issues for non system tokens
1 parent 272f052 commit 57ea2e1

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

app/lib/deepl/client.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ class DeeplInvalidTokenException < StandardError
1717

1818
module Deepl
1919
class Client
20-
attr_accessor :api_endpoint, :api_token
20+
attr_accessor :api_endpoint, :api_token, :custom_deepl_account
2121

2222
def initialize(organization = nil)
2323
if organization&.uses_custom_deepl_account?
24+
@custom_deepl_account = true
2425
@api_token = organization.deepl_api_token
2526
if organization.deepl_api_token_type == 'free'
2627
@api_endpoint = DEEPL_FREE_API
@@ -35,6 +36,7 @@ def initialize(organization = nil)
3536
)
3637
end
3738
else
39+
@custom_deepl_account = false
3840
@api_token = ENV.fetch('DEEPL_API_TOKEN', nil)
3941
@api_endpoint = @api_token&.ends_with?(':fx') ? DEEPL_FREE_API : DEEPL_PRO_API
4042
end
@@ -115,6 +117,11 @@ def translate(text, source_lang, target_lang)
115117
json['translations'][0]['text']
116118
end
117119
end
120+
rescue => e
121+
unless @custom_deepl_account
122+
Sentry.capture_exception(e)
123+
end
124+
nil
118125
end
119126

120127
private

0 commit comments

Comments
 (0)