Skip to content

[Notifier] [Slack] Include additional errors to slack notifier error message #42090

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
Jul 13, 2021
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'));
}
}