R
R
Ruslan2021-08-26 07:14:24
PHP
Ruslan, 2021-08-26 07:14:24

Why is Swift_TransportException not being caught in queue\JobInterface?

In console.php config:

'mailer' => [
            'class' => \yii\swiftmailer\Mailer::class,
            'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'mail.mymail.test',
                'username' => getenv('YII_MAILER_USER'),
                'password' => getenv('YII_MAILER_PASSWORD'),
                'port' => '587',
                'encryption' => 'tls',
            ],
            'useFileTransport' => false,
        ],

Exception not caught in catch
try {
    Yii::$app->mailer->compose()
        ->setFrom('i[email protected]')
        ->setTo('[email protected]_mail_domain.test')
        ->setSubject('test')
        ->send();
}
catch (\Swift_TransportException  $e) {
    $mailed_status = 'ERROR';
    $_mailed_to['error'] = $e->getMessage();
}

If you do the same in a regular controller without queues, then everything works. And here in the console through queue does not want? What's wrong?

Listener tried to run both with and without isolation

yii queue/listen --verbose=1 --color=1 --isolate=0
yii queue/listen --verbose=1 --color=1


The result is always the same:
[email protected]:/var/www/html# /var/www/irp/yii queue/listen --verbose=1 --color=1
2021-08-26 10:30:10 [pid: 94] - Worker is started
2021-08-26 10:30:17 [890] app\modules\system\queue\QueueJobThreatMailing (attempt: 1, pid: 94) - Started
2021-08-26 10:30:20 [890] app\modules\system\queue\QueueJobThreatMailing (attempt: 1, pid: 94) - Error (2.586 s)
> Swift_TransportException: Expected response code 250 but got code "503", with message "503 5.5.1 Error: nested MAIL command


UPD:
Such an exception is caught without problems:
try {
    throw new Exception('Exception!!!');  
}
catch (Exception $e) {
    echo 'Exception has catched: ' . $e->getMessage() . PHP_EOL;
}

2021-08-26 12:18:22 [pid: 116] - Worker is started
2021-08-26 12:18:29 [898] app\modules\system\queue\QueueJobThreatMailing (attempt: 1, pid: 116) - Started
Exception has catched: Exception!!!
2021-08-26 12:18:30 [898] app\modules\system\queue\QueueJobThreatMailing (attempt: 1, pid: 116) - Done (0.254 s)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question