/**
  * @param Message $message
  * @return SendMessageResult
  */
 public function send(Message $message)
 {
     try {
         $result = $this->messagingService->send($message);
     } catch (ApiRuntimeException $e) {
         $this->logger->error(sprintf('Unexpected communication failure with MessageBird; %s', $e->getMessage()), $this->createMessageLogContext($message));
         throw $e;
     }
     if ($result->isMessageInvalid()) {
         $this->logger->notice(sprintf('Invalid message sent to MessageBird (%s)', $result->getErrorsAsString()), $this->createMessageLogContext($message));
     }
     if ($result->isAccessKeyInvalid()) {
         $this->logger->critical(sprintf('Invalid access key used for MessageBird (%s)', $result->getErrorsAsString()), $this->createMessageLogContext($message));
     }
     return $result;
 }
 public function testThrowsApiRuntimeExceptionWhenUnknownStatusCode()
 {
     $this->setExpectedException('Surfnet\\MessageBirdApiClient\\Exception\\ApiRuntimeException', 'Unexpected MessageBird server behaviour');
     $http = new Client();
     $http->getEmitter()->attach(new Mock([__DIR__ . '/fixtures/101-switching-protocols.txt']));
     $messaging = new MessagingService($http);
     $messaging->send(new Message('SURFnet', '31612345678', 'This is a text message.'));
 }