Skip to content
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 @@ -101,7 +101,7 @@ public function testSend()
public function testSendThrowsForErrorResponse()
{
$client = new MockHttpClient(static function (string $method, string $url, array $options): ResponseInterface {
return new MockResponse(json_encode(['Message' => 'i\'m a teapot', 'ErrorCode' => 418]), [
return new MockResponse(json_encode(['error' => 'i\'m a teapot']), [
'http_code' => 418,
'response_headers' => [
'content-type' => 'application/json',
Expand All @@ -118,7 +118,31 @@ public function testSendThrowsForErrorResponse()
->text('Hello There!');

$this->expectException(HttpTransportException::class);
$this->expectExceptionMessage('Unable to send an email: i\'m a teapot (code 418).');
$this->expectExceptionMessage('Unable to send an email: {"error":"i\'m a teapot"}');
$transport->send($mail);
}

public function testSendThrowsForMultipleErrorResponses()
{
$client = new MockHttpClient(static function (string $method, string $url, array $options): ResponseInterface {
return new MockResponse(json_encode(['errors' => ["to" => "undefined field" ]]), [
'http_code' => 418,
'response_headers' => [
'content-type' => 'application/json',
],
]);
});
$transport = new OhMySmtpApiTransport('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: {"errors":{"to":"undefined field"}}');
$transport->send($mail);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected function doSendApi(SentMessage $sentMessage, Email $email, Envelope $e
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we figure out all possibilities instead of "just" dumping the content?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, that's the same on line 64, let's do it that way then.

}

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