From 6bda86a710a7bc5f0ef3acb1628627368a7fd88c Mon Sep 17 00:00:00 2001 From: Priyadi Iman Nurcahyo <1102197+priyadi@users.noreply.github.com> Date: Sat, 7 Sep 2024 19:34:58 +0700 Subject: [PATCH] fix(SymfonySerializerKeysetPageIdentifierEncoder): handle more errors --- CHANGELOG.md | 4 ++++ ...ymfonySerializerKeysetPageIdentifierEncoder.php | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d052293..5f2d442 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +# 0.17.2 + +* fix(`SymfonySerializerKeysetPageIdentifierEncoder`): handle more errors + # 0.17.1 * fix: LIMIT & OFFSET are not supported with replacing select count(*) diff --git a/packages/rekapager-keyset-pagination/src/PageIdentifierEncoder/SymfonySerializerKeysetPageIdentifierEncoder.php b/packages/rekapager-keyset-pagination/src/PageIdentifierEncoder/SymfonySerializerKeysetPageIdentifierEncoder.php index 77b5c35..d287b1f 100644 --- a/packages/rekapager-keyset-pagination/src/PageIdentifierEncoder/SymfonySerializerKeysetPageIdentifierEncoder.php +++ b/packages/rekapager-keyset-pagination/src/PageIdentifierEncoder/SymfonySerializerKeysetPageIdentifierEncoder.php @@ -22,6 +22,7 @@ use Rekalogika\Rekapager\Keyset\Contracts\KeysetPageIdentifier; use Symfony\Component\Serializer\Encoder\DecoderInterface; use Symfony\Component\Serializer\Encoder\EncoderInterface; +use Symfony\Component\Serializer\Exception\UnexpectedValueException; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Uid\AbstractUid; @@ -128,7 +129,11 @@ public function decode(string $encoded): object throw new PageIdentifierDecodingFailureException('Empty encoded identifier'); } - $decoded = Base64Url::decode($encoded); + try { + $decoded = Base64Url::decode($encoded); + } catch (\InvalidArgumentException $e) { + throw new PageIdentifierDecodingFailureException('Failed to decode encoded identifier', previous: $e); + } try { $decoded = gzinflate($decoded); @@ -140,7 +145,12 @@ public function decode(string $encoded): object throw new PageIdentifierDecodingFailureException('Failed to decompress encoded identifier'); } - $array = $this->decoder->decode($decoded, 'json'); + try { + $array = $this->decoder->decode($decoded, 'json'); + + } catch (UnexpectedValueException $e) { + throw new PageIdentifierDecodingFailureException('Failed to decode serialized identifier', previous: $e); + } if (!\is_array($array)) { throw new PageIdentifierDecodingFailureException('Invalid decoded identifier');