Skip to content

Commit 3664426

Browse files
authored
Merge pull request #6 from andrew-demb/catch-json-exception
Do not catch not mentioned in contract exceptions
2 parents 44e6372 + 084e250 commit 3664426

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/JsonSerializer.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace ServiceBus\MessageSerializer;
1414

15+
use ServiceBus\Common\Exceptions\JsonSerializationFailed;
1516
use ServiceBus\MessageSerializer\Exceptions\SerializationFailed;
1617
use ServiceBus\MessageSerializer\Exceptions\UnserializeFailed;
1718
use function ServiceBus\Common\jsonDecode;
@@ -31,12 +32,12 @@ public function serialize(array $payload): string
3132
{
3233
return jsonEncode($payload);
3334
}
34-
catch (\Throwable $throwable)
35+
catch (JsonSerializationFailed $jsonError)
3536
{
3637
throw new SerializationFailed(
37-
\sprintf('JSON serialize failed: %s', $throwable->getMessage()),
38-
(int) $throwable->getCode(),
39-
$throwable
38+
\sprintf('JSON serialize failed: %s', $jsonError->getMessage()),
39+
(int) $jsonError->getCode(),
40+
$jsonError
4041
);
4142
}
4243
}
@@ -50,12 +51,12 @@ public function unserialize(string $content): array
5051
{
5152
return jsonDecode($content);
5253
}
53-
catch (\Throwable $throwable)
54+
catch (JsonSerializationFailed $jsonError)
5455
{
5556
throw new UnserializeFailed(
56-
\sprintf('JSON unserialize failed: %s', $throwable->getMessage()),
57-
(int) $throwable->getCode(),
58-
$throwable
57+
\sprintf('JSON unserialize failed: %s', $jsonError->getMessage()),
58+
(int) $jsonError->getCode(),
59+
$jsonError
5960
);
6061
}
6162
}

0 commit comments

Comments
 (0)