Translating job items - Quota full - Internal Server Error

Created on 10 May 2023, over 1 year ago
Updated 1 June 2023, over 1 year ago

Problem/Motivation

If the quota of the API is used up, then an internal error is issued.

Error on Webserver
AH01071: Got error 'PHP message: Uncaught PHP Exception Drupal\\tmgmt\\TMGMTException: "DeepL API service returned following error: Quota Exceeded" at /web/modules/contrib/tmgmt_deepl/src/Plugin/tmgmt/Translator/DeeplTranslator.php line 337'

🐛 Bug report
Status

Active

Version

2.1

Component

Code

Created by

🇨🇭Switzerland szeberli

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

Comments & Activities

  • Issue created by @szeberli
  • 🇩🇪Germany SteffenR Germany

    Thanks for the finding. The issue is caused by a missing exception handling in the batchRequestTranslation callback.

    We need to improve the exception handling in the batchRequestTranslation callback.
    The self::doRequest needs to be wrapped into a try/ catch block.

    try {
          $result = self::doRequest($job, $query_params);
          // Collect translated texts with use of initial keys.
          foreach ($result['translations'] as $translated) {
            $translation[$keys_sequence[$i]]['#text'] = rawurldecode(Html::decodeEntities($translated['text']));
            $i++;
          }
          if (isset($context['results']) && isset($context['results']['translation']) && $context['results']['translation'] != NULL) {
            $context['results']['translation'] = array_merge($context['results']['translation'], $translation);
          }
          else {
            $context['results']['translation'] = $translation;
          }
          $context['results']['i'] = $i;
        } catch (TMGMTException $e) {
          \Drupal::messenger()->addError($e->getMessage());
        }
    

    To overcome issues of incomplete translations in case of an error, the actual translation job needs to be resetted or deleted (needs to be evaluated) in the batchFinished callback.

Production build 0.71.5 2024