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 ); } }