Skip to content

Commit

Permalink
fix(SymfonySerializerKeysetPageIdentifierEncoder): handle more errors
Browse files Browse the repository at this point in the history
  • Loading branch information
priyadi committed Sep 7, 2024
1 parent 30e8691 commit 6bda86a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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(*)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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');
Expand Down

0 comments on commit 6bda86a

Please sign in to comment.