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 18c1498

Browse filesBrowse files
committed
Include additional errors to slack notifier error message
1 parent 01613b1 commit 18c1498
Copy full SHA for 18c1498

File tree

Expand file treeCollapse file tree

2 files changed

+31
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+31
-1
lines changed

‎src/Symfony/Component/Notifier/Bridge/Slack/SlackTransport.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Slack/SlackTransport.php
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ protected function doSend(MessageInterface $message): SentMessage
9595

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

101103
$sentMessage = new SentMessage($message, (string) $this);

‎src/Symfony/Component/Notifier/Bridge/Slack/Tests/SlackTransportTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Slack/Tests/SlackTransportTest.php
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,32 @@ public function testSendIncludesContentTypeWithCharset()
239239

240240
$transport->send(new ChatMessage('testMessage'));
241241
}
242+
243+
public function testSendWithErrorsIncluded()
244+
{
245+
$response = $this->createMock(ResponseInterface::class);
246+
247+
$response->expects($this->exactly(2))
248+
->method('getStatusCode')
249+
->willReturn(200);
250+
251+
$response->expects($this->once())
252+
->method('getContent')
253+
->willReturn(json_encode([
254+
'ok' => false,
255+
'error' => 'invalid_blocks',
256+
'errors' => ['no more than 50 items allowed [json-pointer:/blocks]'],
257+
]));
258+
259+
$client = new MockHttpClient(function () use ($response): ResponseInterface {
260+
return $response;
261+
});
262+
263+
$transport = $this->createTransport($client, 'testChannel');
264+
265+
$this->expectException(TransportException::class);
266+
$this->expectExceptionMessage('Unable to post the Slack message: "invalid_blocks" (no more than 50 items allowed [json-pointer:/blocks]).');
267+
268+
$transport->send(new ChatMessage('testMessage'));
269+
}
242270
}

0 commit comments

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