1
0
mirror of https://github.com/flarum/core.git synced 2025-08-04 15:37:51 +02:00

Restore error details in JSON-API error formatter

Fixes #1865. Refs #1843.
This commit is contained in:
Franz Liedke
2019-09-04 01:44:22 +02:00
parent 3eb28dfb16
commit dcf88df0c7
2 changed files with 41 additions and 6 deletions

View File

@@ -26,12 +26,21 @@ class JsonApiFormatter implements HttpFormatter
public function format(HandledError $error, Request $request): Response
{
$document = new Document;
$document->setErrors([
[
'status' => (string) $error->getStatusCode(),
'code' => $error->getType(),
],
]);
$data = [
'status' => (string) $error->getStatusCode(),
'code' => $error->getType(),
];
$details = $error->getDetails();
if (empty($details)) {
$document->setErrors([$data]);
} else {
$document->setErrors(array_map(
function ($row) use ($data) { return array_merge($data, $row); },
$details
));
}
return new JsonApiResponse($document, $error->getStatusCode());
}