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 @@ -95,7 +95,9 @@ protected function doSend(MessageInterface $message): SentMessage

$result = $response->toArray(false);
if (!$result['ok']) {
throw new TransportException(sprintf('Unable to post the Slack message: "%s".', $result['error']), $response);
$errors = isset($result['errors']) ? ' ('.implode('|', $result['errors']).')' : '';

throw new TransportException(sprintf('Unable to post the Slack message: "%s"%s.', $result['error'], $errors), $response);
}

$sentMessage = new SentMessage($message, (string) $this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,32 @@ public function testSendIncludesContentTypeWithCharset()

$transport->send(new ChatMessage('testMessage'));
}

public function testSendWithErrorsIncluded()
{
$response = $this->createMock(ResponseInterface::class);

$response->expects($this->exactly(2))
->method('getStatusCode')
->willReturn(200);

$response->expects($this->once())
->method('getContent')
->willReturn(json_encode([
'ok' => false,
'error' => 'invalid_blocks',
'errors' => ['no more than 50 items allowed [json-pointer:/blocks]'],
]));

$client = new MockHttpClient(function () use ($response): ResponseInterface {
return $response;
});

$transport = $this->createTransport($client, 'testChannel');

$this->expectException(TransportException::class);
$this->expectExceptionMessage('Unable to post the Slack message: "invalid_blocks" (no more than 50 items allowed [json-pointer:/blocks]).');

$transport->send(new ChatMessage('testMessage'));
}
}