Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Mailer] [MailPace] Fix undefined array key in errors response #50515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,57 @@ public function testSendThrowsForErrorResponse()
$transport->send($mail);
}

public function testSendThrowsForErrorsResponse()
{
$client = new MockHttpClient(static function (string $method, string $url, array $options): ResponseInterface {
return new MockResponse(json_encode([
'errors' => [
'to' => [
'contains a blocked address',
'number of email addresses exceeds maximum volume',
],
'attachments.name' => ['Extension file type blocked, see Docs for full list of allowed file types'],
],
]), [
'http_code' => 400,
'response_headers' => [
'content-type' => 'application/json',
],
]);
});
$transport = new MailPaceApiTransport('KEY', $client);
$transport->setPort(8984);

$mail = new Email();
$mail->subject('Hello!')
->to(new Address('saif.gmati@symfony.com', 'Saif Eddin'))
->from(new Address('fabpot@symfony.com', 'Fabien'))
->text('Hello There!');

$this->expectException(HttpTransportException::class);
$this->expectExceptionMessage('Unable to send an email: to: contains a blocked address & number of email addresses exceeds maximum volume; attachments.name: Extension file type blocked, see Docs for full list of allowed file types (code 400).');
$transport->send($mail);
}

public function testSendThrowsForInternalServerErrorResponse()
{
$client = new MockHttpClient(static function (string $method, string $url, array $options): ResponseInterface {
return new MockResponse('', ['http_code' => 500]);
});
$transport = new MailPaceApiTransport('KEY', $client);
$transport->setPort(8984);

$mail = new Email();
$mail->subject('Hello!')
->to(new Address('saif.gmati@symfony.com', 'Saif Eddin'))
->from(new Address('fabpot@symfony.com', 'Fabien'))
->text('Hello There!');

$this->expectException(HttpTransportException::class);
$this->expectExceptionMessage('Unable to send an email: (code 500).');
$transport->send($mail);
}

public function testTagAndMetadataHeaders()
{
$email = new Email();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,20 @@ protected function doSendApi(SentMessage $sentMessage, Email $email, Envelope $e
}

if (200 !== $statusCode) {
throw new HttpTransportException('Unable to send an email: '.$result['error'].sprintf(' (code %d).', $statusCode), $response);
$errorMessage = 'Unable to send an email: ';
if (isset($result['error'])) {
$errorMessage .= $result['error'];
} elseif (isset($result['errors'])) {
$errors = [];
foreach ($result['errors'] as $key => $val) {
$errors[] = $key.': '.implode(' & ', $val);
}
$errorMessage .= implode('; ', $errors);
} else {
$errorMessage .= 'unknown error';
}
$errorMessage .= sprintf(' (code %d).', $statusCode);
throw new HttpTransportException($errorMessage, $response);
}

$sentMessage->setMessageId($result['id']);
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.