1111use Symfony \Component \Messenger \Middleware \MiddlewareInterface ;
1212use Symfony \Component \Messenger \Middleware \StackInterface ;
1313use Symfony \Component \Messenger \Stamp \BusNameStamp ;
14+ use Symfony \Component \Messenger \Stamp \HandledStamp ;
1415use Symfony \Component \Messenger \Stamp \HandlerArgumentsStamp ;
1516use Symfony \Component \String \ByteString ;
1617use Throwable ;
@@ -33,11 +34,12 @@ public function handle(Envelope $envelope, StackInterface $stack): Envelope
3334 return $ stack ->next ()->handle ($ envelope , $ stack );
3435 } catch (Exception $ exception ) {
3536 $ exceptionBusName = $ this ->getExceptionBusName ($ busName );
37+ $ handledExceptionEnvelope = $ this ->handleException ($ exceptionBusName , $ exception , $ message );
3638
37- return $ this -> exceptionHandlerBus -> dispatch (
38- Envelope:: wrap ( $ exception , [ new BusNameStamp ( $ exceptionBusName )]),
39- [ new HandlerArgumentsStamp ([ $ message ])],
40- );
39+ /** @var list<HandledStamp> $handledExceptionStamps */
40+ $ handledExceptionStamps = $ handledExceptionEnvelope -> all (HandledStamp::class);
41+
42+ return $ envelope -> with (... $ handledExceptionStamps );
4143 }
4244 }
4345
@@ -56,4 +58,12 @@ private function getExceptionBusName(ByteString $busName): string
5658 {
5759 return $ busName ->trimSuffix ('.bus ' )->append ('.exception.bus ' )->toString ();
5860 }
61+
62+ private function handleException (string $ exceptionBusName , Exception $ exception , object $ message ): Envelope
63+ {
64+ return $ this ->exceptionHandlerBus ->dispatch (
65+ Envelope::wrap ($ exception , [new BusNameStamp ($ exceptionBusName )]),
66+ [new HandlerArgumentsStamp ([$ message ])],
67+ );
68+ }
5969}
0 commit comments