bug #36635 [Notifier] Fix 3 errors for bridge Mattermost (Sébastien COURJEAN)

This PR was squashed before being merged into the 5.1-dev branch.

Discussion
----------

[Notifier] Fix 3 errors for bridge Mattermost

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #36632
| License       | MIT
| Doc PR        | symfony/symfony-docs#...

Fix 3 errors for bridge mattermost in notifier component.

Commits
-------

ca9439ac43 [Notifier] Fix 3 errors for bridge Mattermost
This commit is contained in:
Fabien Potencier 2020-05-01 08:02:37 +02:00
commit da6620c035

View File

@ -56,7 +56,7 @@ final class MattermostTransport extends AbstractTransport
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, ChatMessage::class, get_debug_type($message)));
}
$endpoint = sprintf('https://%s/api/v4/post', $this->getEndpoint());
$endpoint = sprintf('https://%s/api/v4/posts', $this->getEndpoint());
$options = ($opts = $message->getOptions()) ? $opts->toArray() : [];
$options['message'] = $message->getSubject();
@ -65,11 +65,11 @@ final class MattermostTransport extends AbstractTransport
$options['channel_id'] = $message->getRecipientId() ?: $this->channel;
}
$response = $this->client->request('POST', $endpoint, [
'bearer' => $this->token,
'auth_bearer' => $this->token,
'json' => array_filter($options),
]);
if (200 !== $response->getStatusCode()) {
if (201 !== $response->getStatusCode()) {
$result = $response->toArray(false);
throw new TransportException(sprintf('Unable to post the Mattermost message: %s (%s).', $result['message'], $result['id']), $response);