|
5 | 5 | use Psr\Log\LoggerInterface;
|
6 | 6 | use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
7 | 7 | use Symfony\Component\Form\FormInterface;
|
| 8 | +use Symfony\Component\HttpFoundation\Exception\JsonException; |
8 | 9 | use Symfony\Component\HttpFoundation\Request;
|
9 | 10 | use Torr\Rad\Exception\Request\InvalidJsonRequestException;
|
10 | 11 | use Torr\Rad\Form\FormErrorNormalizer;
|
@@ -72,29 +73,18 @@ public function fetchJsonRequestBody (Request $request, bool $allowInvalid = fal
|
72 | 73 | throw new InvalidJsonRequestException("Expected JSON request content type.", 415);
|
73 | 74 | }
|
74 | 75 |
|
75 |
| - $raw = trim((string) $request->getContent()); |
76 |
| - |
77 |
| - if ("" === $raw) |
78 |
| - { |
79 |
| - return []; |
80 |
| - } |
81 |
| - |
82 | 76 | try
|
83 | 77 | {
|
84 |
| - $data = json_decode($raw, true, 512, \JSON_THROW_ON_ERROR); |
85 |
| - |
86 |
| - if (!\is_array($data)) |
87 |
| - { |
88 |
| - throw new InvalidJsonRequestException( |
89 |
| - \sprintf("Invalid top level type in JSON payload. Must be array, is %s", \gettype($data)), |
90 |
| - 400, |
91 |
| - ); |
92 |
| - } |
93 |
| - |
94 |
| - return $data; |
| 78 | + return $request->getPayload()->all(); |
95 | 79 | }
|
96 |
| - catch (\JsonException $exception) |
| 80 | + catch (JsonException $exception) |
97 | 81 | {
|
| 82 | + $this->getLogger()->error("Parsing JSON payload failed: {message}", [ |
| 83 | + "message" => $exception->getMessage(), |
| 84 | + "exception" => $exception, |
| 85 | + "json" => (string) $request->getContent(), |
| 86 | + ]); |
| 87 | + |
98 | 88 | throw new InvalidJsonRequestException(
|
99 | 89 | \sprintf("Parsing JSON payload failed: %s", $exception->getMessage()),
|
100 | 90 | 400,
|
|
0 commit comments