Improve logging of errors and exceptions

Created on 7 November 2022, about 2 years ago
Updated 19 June 2023, over 1 year ago

Problem/Motivation

API returns detailed error messages on exceptions in response:

{
  "ErrorCode": "string",
  "Message": "string"
}

But the actual logged error message in Drupal is only taken from exception getMessage() method.

Steps to reproduce

Configure the translator with unavailable language pair. Try to request translation. The logged error message will be: "Conflict", with no more details. The actual response with exception is:

Client error: `POST /memoqservercmsgateway/v1/orders/221101-ZN0/jobs` resulted in a `409 Conflict` response:
{"ErrorCode":"TranslationJobLangPairIsNotSupported","Message":"The language pair is not supported by the connection."}

Proposed resolution

Add to logs the Message from response, not from exception response getReasonPhrase() that returns the label of status

Remaining tasks

Create patch or MR

User interface changes

No changes.

API changes

No changes.

Data model changes

No changes.

Feature request
Status

Needs review

Version

1.0

Component

Code

Created by

🇩🇪Germany a.dmitriiev

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇨🇭Switzerland berdir Switzerland
    +++ b/src/Plugin/tmgmt/Translator/MemoQTranslator.php
    @@ -182,7 +195,7 @@ class MemoQTranslator extends TranslatorPluginBase implements ContainerFactoryPl
         }
         catch (TMGMTException $e) {
    -      \Drupal::logger('tmgmt_memoq')->error('Job has been rejected with following error: @error',
    +      $this->logger->error('Job has been rejected with following error: @error',
             ['@error' => $e->getMessage()]);
           $job->rejected('Job has been rejected with following error: @error',
    

    not injecting/defining this as a service was done kind of on purpose. Log channels and the logger factory are quite heavy services as all the loggers get initialized and we only need it if something goes wrong.

  • 🇩🇪Germany a.dmitriiev

    Here is the new patch without dependency injection for logger. No interdiff, because the previous patch doesn't apply anymore.

  • 🇩🇪Germany a.dmitriiev

    @Berdir, is there anything else that I can do here? Please let me know.

Production build 0.71.5 2024