Skip to content

Commit

Permalink
Fix reporting of deepl issues for non system tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
chrztoph committed Dec 18, 2024
1 parent 272f052 commit 57ea2e1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/lib/deepl/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ class DeeplInvalidTokenException < StandardError

module Deepl
class Client
attr_accessor :api_endpoint, :api_token
attr_accessor :api_endpoint, :api_token, :custom_deepl_account

def initialize(organization = nil)
if organization&.uses_custom_deepl_account?
@custom_deepl_account = true
@api_token = organization.deepl_api_token
if organization.deepl_api_token_type == 'free'
@api_endpoint = DEEPL_FREE_API
Expand All @@ -35,6 +36,7 @@ def initialize(organization = nil)
)
end
else
@custom_deepl_account = false
@api_token = ENV.fetch('DEEPL_API_TOKEN', nil)
@api_endpoint = @api_token&.ends_with?(':fx') ? DEEPL_FREE_API : DEEPL_PRO_API
end
Expand Down Expand Up @@ -115,6 +117,11 @@ def translate(text, source_lang, target_lang)
json['translations'][0]['text']
end
end
rescue => e
unless @custom_deepl_account
Sentry.capture_exception(e)
end
nil
end

private
Expand Down

0 comments on commit 57ea2e1

Please sign in to comment.