Skip to content

Instantly share code, notes, and snippets.

@sanslan
Last active February 25, 2022 08:45
Show Gist options
  • Save sanslan/f418550c7637ee84f61af9335f7d90ec to your computer and use it in GitHub Desktop.
Save sanslan/f418550c7637ee84f61af9335f7d90ec to your computer and use it in GitHub Desktop.
<?php
class APINormalizer implements NormalizerInterface
{
public function normalize($exception, string $format = null, array $context = [])
{
if($exception instanceof NotFoundHttpException){
return [
'exception'=> [
'message' => $exception->getMessage(),
'code' => $exception->getStatusCode(),
],
];
}
return [
'content' => 'This is my custom problem normalizer.',
'exception'=> [
'message' => $exception->getMessage(),
'code' => $exception->getStatusCode(),
],
];
}
public function supportsNormalization($data, string $format = null)
{
return $data instanceof FlattenException;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment