From 084e2505c27d2cecfbfb3f0f1db20daf2f7b3b76 Mon Sep 17 00:00:00 2001 From: lalshe Date: Wed, 4 Dec 2019 20:52:12 +0200 Subject: [PATCH] Do not catch not mentioned in contract exceptions --- src/JsonSerializer.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/JsonSerializer.php b/src/JsonSerializer.php index 915f69b..c10ea83 100644 --- a/src/JsonSerializer.php +++ b/src/JsonSerializer.php @@ -12,6 +12,7 @@ namespace ServiceBus\MessageSerializer; +use ServiceBus\Common\Exceptions\JsonSerializationFailed; use ServiceBus\MessageSerializer\Exceptions\SerializationFailed; use ServiceBus\MessageSerializer\Exceptions\UnserializeFailed; use function ServiceBus\Common\jsonDecode; @@ -31,12 +32,12 @@ public function serialize(array $payload): string { return jsonEncode($payload); } - catch (\Throwable $throwable) + catch (JsonSerializationFailed $jsonError) { throw new SerializationFailed( - \sprintf('JSON serialize failed: %s', $throwable->getMessage()), - (int) $throwable->getCode(), - $throwable + \sprintf('JSON serialize failed: %s', $jsonError->getMessage()), + (int) $jsonError->getCode(), + $jsonError ); } } @@ -50,12 +51,12 @@ public function unserialize(string $content): array { return jsonDecode($content); } - catch (\Throwable $throwable) + catch (JsonSerializationFailed $jsonError) { throw new UnserializeFailed( - \sprintf('JSON unserialize failed: %s', $throwable->getMessage()), - (int) $throwable->getCode(), - $throwable + \sprintf('JSON unserialize failed: %s', $jsonError->getMessage()), + (int) $jsonError->getCode(), + $jsonError ); } }