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

Commit 3bebc64

Browse filesBrowse files
committed
[Mailer] Fix Error Handling for OhMySMTP Bridge
1 parent deb04f2 commit 3bebc64
Copy full SHA for 3bebc64

File tree

2 files changed

+27
-3
lines changed
Filter options

2 files changed

+27
-3
lines changed

‎src/Symfony/Component/Mailer/Bridge/OhMySmtp/Tests/Transport/OhMySmtpApiTransportTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Bridge/OhMySmtp/Tests/Transport/OhMySmtpApiTransportTest.php
+26-2Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function testSend()
101101
public function testSendThrowsForErrorResponse()
102102
{
103103
$client = new MockHttpClient(static function (string $method, string $url, array $options): ResponseInterface {
104-
return new MockResponse(json_encode(['Message' => 'i\'m a teapot', 'ErrorCode' => 418]), [
104+
return new MockResponse(json_encode(['error' => 'i\'m a teapot']), [
105105
'http_code' => 418,
106106
'response_headers' => [
107107
'content-type' => 'application/json',
@@ -118,7 +118,31 @@ public function testSendThrowsForErrorResponse()
118118
->text('Hello There!');
119119

120120
$this->expectException(HttpTransportException::class);
121-
$this->expectExceptionMessage('Unable to send an email: i\'m a teapot (code 418).');
121+
$this->expectExceptionMessage('Unable to send an email: {"error":"i\'m a teapot"}');
122+
$transport->send($mail);
123+
}
124+
125+
public function testSendThrowsForMultipleErrorResponses()
126+
{
127+
$client = new MockHttpClient(static function (string $method, string $url, array $options): ResponseInterface {
128+
return new MockResponse(json_encode(['errors' => ["to" => "undefined field" ]]), [
129+
'http_code' => 418,
130+
'response_headers' => [
131+
'content-type' => 'application/json',
132+
],
133+
]);
134+
});
135+
$transport = new OhMySmtpApiTransport('KEY', $client);
136+
$transport->setPort(8984);
137+
138+
$mail = new Email();
139+
$mail->subject('Hello!')
140+
->to(new Address('saif.gmati@symfony.com', 'Saif Eddin'))
141+
->from(new Address('fabpot@symfony.com', 'Fabien'))
142+
->text('Hello There!');
143+
144+
$this->expectException(HttpTransportException::class);
145+
$this->expectExceptionMessage('Unable to send an email: {"errors":{"to":"undefined field"}}');
122146
$transport->send($mail);
123147
}
124148

‎src/Symfony/Component/Mailer/Bridge/OhMySmtp/Transport/OhMySmtpApiTransport.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Bridge/OhMySmtp/Transport/OhMySmtpApiTransport.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected function doSendApi(SentMessage $sentMessage, Email $email, Envelope $e
6767
}
6868

6969
if (200 !== $statusCode) {
70-
throw new HttpTransportException('Unable to send an email: '.$result['Message'].sprintf(' (code %d).', $result['ErrorCode']), $response);
70+
throw new HttpTransportException('Unable to send an email: '.$response->getContent(false), $response);
7171
}
7272

7373
$sentMessage->setMessageId($result['id']);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.