Problem/Motivation

If the Postmark API key is missing or wrong and an attempt is made to send an email, then Postmark generates an exception "PostmarkException" that contains the message

Unauthorized: Missing or incorrect API token in header. Please verify that you used the correct token when you constructed your client.

The entry posted to the DB log has

     $this->logger->error('Postmark exception occurred while trying to send email from %from to %to. @code: @message',
        [
          '%from' => $sender_signature,
          '%to' => $params['to'],
          '@code' => $e->postmarkApiErrorCode,
          '@message' => $e->message,
        ]

but the value $e->postmarkApiErrorCode is NULL. This causes Html::escape() to throw a TypeError when the dblog view renders the entry

Steps to reproduce

Load an invalid API key and send a test message, then check the DB log.

Proposed resolution

Update the log call to read:

      $this->logger->error('Postmark exception occurred while trying to send email from %from to %to. @code: @message',
        [
          '%from' => $sender_signature,
          '%to' => $params['to'],
          '@code' => $e->postmarkApiErrorCode ?? '',
          '@message' => $e->message ?? '',
        ]

Issue fork postmark-3594060

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jayelless created an issue. See original summary.

dkmishra made their first commit to this issue’s fork.

dkmishra’s picture

Status: Active » Needs review
i-trokhanenko’s picture

Status: Needs review » Reviewed & tested by the community

  • 45d93e69 committed on 8.x-1.x
    Issue #3594060: Prevent DB log error for invalid Postmark API token
    
i-trokhanenko’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.