Skip to content

Commit

Permalink
cs: run php-cs-fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Dec 13, 2024
1 parent 33f79ab commit 756187f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Serializer/ErrorNormalizerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace ApiPlatform\JsonApi\Serializer;

use ApiPlatform\Exception\ErrorCodeSerializableInterface;
use Symfony\Component\ErrorHandler\Exception\FlattenException;
use Symfony\Component\HttpFoundation\Response;

Expand All @@ -39,15 +40,15 @@ private function getErrorMessage($object, array $context, bool $debug = false):
private function getErrorCode(object $object): ?string
{
if ($object instanceof FlattenException) {
return (string)$object->getStatusCode();
$exceptionClass = $object->getClass();
} else {
$exceptionClass = $object::class;
}

if ($object instanceof \Exception) {
$code = $object->getCode();
return $code !== 0 ? (string)$code : null;
if (is_a($exceptionClass, ErrorCodeSerializableInterface::class, true)) {
return $exceptionClass::getErrorCode();
}

return null;
}
}

0 comments on commit 756187f

Please sign in to comment.