Improve error handling when authentication failed

Created on 25 September 2024, about 2 months ago

Problem/Motivation

Currently the following code in DeepLTranslator.php has the following logic:

try {
   $translator = new Translator($this->config['api_key'], $options);
    $translated = $translator->translateText($text, NULL, $targetLang, $options);
 }
 catch (\Exception $e) {
   return $text;
 }

This can cause confusion when the actual API key is not working because the exception returns the original text instead of the translation and gives the following message to the end user:
The text and its translation are the same so maybe there was an error trying to translate it. Was the text already written on the current language?

The actual exception includes a lot more information. The exception message in our case was:
"Authorization failure, check authentication key, ". The reason for the exception is not obvious in the UI.

Steps to reproduce

1. Configure the module with an API key that does not work.
2. Try to translate the text.

Proposed resolution

We should log the exception in dblog and perhaps also add an additional error message for the end user when authentication fails.

This could for example happen when an existing API Key is deactivated from DeepL.

Remaining tasks

Add error handling in the case that there is an exception from DeepL.

User interface changes

Show a better error message for the end user when the API key is not working. Currently the message is a bit confusing when the page language is different than the original text.

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇫🇮Finland heikkiy Oulu

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024