Skip to content

Commit

Permalink
Merge pull request #60 from fcastilloes/master
Browse files Browse the repository at this point in the history
Release 1.2.0
  • Loading branch information
fcastilloes committed Sep 1, 2017
2 parents f781a24 + 42a0a9c commit c2a363f
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [1.2.0] - 2017-09-01
## Added
- Start support for katana 1.2
## Fixed
- Catch msgpack Packing Exceptions

## [1.1.10] - 2017-08-14
## Fixed
- Fixed Response accessors for attributes
Expand Down
21 changes: 21 additions & 0 deletions src/Exception/ResponderException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* PHP 7 SDK for the KATANA(tm) Framework (http://katana.kusanagi.io)
* Copyright (c) 2016-2017 KUSANAGI S.L. All rights reserved.
*
* Distributed under the MIT license
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code
*
* @link https://github.com/kusanagi/katana-sdk-php7
* @license http://www.opensource.org/licenses/mit-license.php MIT License
* @copyright Copyright (c) 2016-2017 KUSANAGI S.L. (http://kusanagi.io)
*/

namespace Katana\Sdk\Exception;

class ResponderException extends \RuntimeException
{

}
12 changes: 11 additions & 1 deletion src/Executor/AbstractExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Katana\Sdk\Api\Factory\ApiFactory;
use Katana\Sdk\Api\Mapper\PayloadWriterInterface;
use Katana\Sdk\Console\CliInput;
use Katana\Sdk\Exception\ResponderException;
use Katana\Sdk\Logger\KatanaLogger;
use Katana\Sdk\Messaging\Responder\ResponderInterface;
use Throwable;
Expand Down Expand Up @@ -81,7 +82,16 @@ protected function executeCallback(
}

if ($response instanceof Api) {
$this->responder->sendResponse($response, $this->mapper);
try {
$this->responder->sendResponse($response, $this->mapper);
} catch (ResponderException $e) {
$this->sendError($e->getMessage());
if ($e->getPrevious()) {
$this->logger->error(
'Packer error: ' . $e->getPrevious()->getMessage()
);
}
}

return true;
}
Expand Down
18 changes: 12 additions & 6 deletions src/Messaging/Responder/ZeroMqMultipartResponder.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
use Katana\Sdk\Api\Mapper\PayloadWriterInterface;
use Katana\Sdk\Api\RequestApi;
use Katana\Sdk\Api\ResponseApi;
use Katana\Sdk\Exception\ResponderException;
use Katana\Sdk\Messaging\MessagePackSerializer;
use MessagePack\Exception\PackingFailedException;

/**
* Take an Api and respond with a msgpack to ZeroMQ
Expand Down Expand Up @@ -117,12 +119,16 @@ public function __construct(MessagePackSerializer $serializer, $socket)
*/
public function sendResponse(Api $api, PayloadWriterInterface $mapper)
{
if ($api instanceof ActionApi) {
$this->sendActionResponse($api, $mapper);
} elseif ($api instanceof ResponseApi) {
$this->sendResponseResponse($api, $mapper);
} elseif ($api instanceof RequestApi) {
$this->sendRequestResponse($api, $mapper);
try {
if ($api instanceof ActionApi) {
$this->sendActionResponse($api, $mapper);
} elseif ($api instanceof ResponseApi) {
$this->sendResponseResponse($api, $mapper);
} elseif ($api instanceof RequestApi) {
$this->sendRequestResponse($api, $mapper);
}
} catch (PackingFailedException $e) {
throw new ResponderException('Could not pack the message', 1, $e);
}
}

Expand Down

0 comments on commit c2a363f

Please sign in to comment.