Skip to content

Commit 0ad0b4b

Browse files
committed
cs: run php-cs-fixer
1 parent a580a4e commit 0ad0b4b

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/JsonApi/Serializer/ErrorNormalizerTrait.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace ApiPlatform\JsonApi\Serializer;
1515

16+
use ApiPlatform\Exception\ErrorCodeSerializableInterface;
1617
use Symfony\Component\ErrorHandler\Exception\FlattenException;
1718
use Symfony\Component\HttpFoundation\Response;
1819

@@ -39,15 +40,15 @@ private function getErrorMessage($object, array $context, bool $debug = false):
3940
private function getErrorCode(object $object): ?string
4041
{
4142
if ($object instanceof FlattenException) {
42-
return (string)$object->getStatusCode();
43+
$exceptionClass = $object->getClass();
44+
} else {
45+
$exceptionClass = $object::class;
4346
}
4447

45-
if ($object instanceof \Exception) {
46-
$code = $object->getCode();
47-
return $code !== 0 ? (string)$code : null;
48+
if (is_a($exceptionClass, ErrorCodeSerializableInterface::class, true)) {
49+
return $exceptionClass::getErrorCode();
4850
}
4951

5052
return null;
5153
}
5254
}
53-

0 commit comments

Comments
 (0)