/** * @expectedException \Jalle19\StatusManager\Exception\UnknownRequestException */ public function testUnknownRequest() { Factory::factory(json_encode(['type' => 'totally invalid'])); }
/** * Dispatches incoming client messages to the appropriate handlers * * @param ConnectionInterface $from * @param string $msg */ public function onMessage(ConnectionInterface $from, $msg) { try { $message = MessageFactory::factory($msg); $this->logger->debug('Got message from client (type: {messageType})', ['messageType' => $message->getType()]); // Attempt to delegate the message try { $response = $this->tryDelegateMessage($message, $from); $this->sendMessage($response, $from); } catch (RequestFailedException $e) { $this->logger->error('The request failed: ' . $e->getMessage()); } catch (UnhandledMessageException $e) { $this->logger->error('Unhandled message (type: {messageType})', ['messageType' => $message->getType()]); } } catch (MalformedRequestException $e) { $this->logger->error('Got malformed message from client (reason: {reason})', ['reason' => $e->getMessage()]); } catch (UnknownRequestException $e) { // The server itself sometimes sends out messages that are received here, hence debug $this->logger->debug('Got unknown message from client (type: {messageType})', ['messageType' => $e->getType()]); } }