Skip to content

Commit 703eb0e

Browse files
authored
[Events] Skip message dispatch on subscriber when decoration fails (#7)
* [Exceptions] Create custom Invalid payload exception * [Events] Add try..catch on decorate call when dispatching events * [Changelog] Add event dispatch change to changelog 2.1 md * Fix class name in invalid payload exception * [Events] Add type of exception thrown in abstract function decorate
1 parent ff0fb20 commit 703eb0e

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

CHANGELOG-2.1.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ in all versions (major and minor)
77
To get the diff for a specific change, go to https://github.com/PandaPlatform/framework/commit/XXX where
88
XXX is the change hash
99

10+
* 2.1.11
11+
* [Events] Add try..catch on decorate call when dispatching events
12+
1013
* 2.1.10
1114
* [Routing] Log the request not found information
1215

src/Panda/Events/Event.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Panda\Events\Channels\ChannelInterface;
1616
use Panda\Events\Messages\DecoratorInterface;
1717
use Panda\Events\Messages\MessageInterface;
18+
use Panda\Support\Exceptions\InvalidPayloadException;
1819

1920
/**
2021
* Class Event
@@ -42,6 +43,7 @@ abstract public function getChannelFactory();
4243
* @param ChannelInterface $channel
4344
*
4445
* @return MessageInterface
46+
* @throws InvalidPayloadException
4547
*/
4648
abstract public function decorate(MessageInterface $message, ChannelInterface $channel = null);
4749

@@ -72,8 +74,13 @@ public function dispatch()
7274
// Get proper message for the given channel
7375
$message = $this->getMessage($channel);
7476

75-
// Decorate message
76-
$message = $this->decorate($message, $channel);
77+
try {
78+
// Decorate message
79+
$message = $this->decorate($message, $channel);
80+
} catch (InvalidPayloadException $ex) {
81+
// Continue to next subscriber
82+
continue;
83+
}
7784

7885
// Dispatch to all subscribers
7986
/** @var SubscriberInterface $subscriber */
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Panda framework.
5+
*
6+
* (c) Ioannis Papikas <papikas.ioan@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Panda\Support\Exceptions;
13+
14+
use Exception;
15+
16+
/**
17+
* Class InvalidPayloadException
18+
* @package Panda\Support\Exceptions
19+
*/
20+
class InvalidPayloadException extends Exception
21+
{
22+
}

0 commit comments

Comments
 (0)