Fix Internal Server Error for blank API requests

Attempting to send an empty body to the create and update endpoints will
result in Flarum outputting "Internal Server Error" as plain text,
instead of failing gracefully with a json-ised validation exception.

This commit adds an empty array as the third parameter to array_get,
which sets the default value and thus allows Flarum to do its thing.
This commit is contained in:
Dave Shoreman 2017-04-06 04:16:40 +01:00
parent be643a1e4b
commit fb8ad8fe9a
2 changed files with 2 additions and 2 deletions

View File

@ -44,7 +44,7 @@ class CreateTagController extends AbstractCreateController
protected function data(ServerRequestInterface $request, Document $document) protected function data(ServerRequestInterface $request, Document $document)
{ {
return $this->bus->dispatch( return $this->bus->dispatch(
new CreateTag($request->getAttribute('actor'), array_get($request->getParsedBody(), 'data')) new CreateTag($request->getAttribute('actor'), array_get($request->getParsedBody(), 'data', []))
); );
} }
} }

View File

@ -45,7 +45,7 @@ class UpdateTagController extends AbstractResourceController
{ {
$id = array_get($request->getQueryParams(), 'id'); $id = array_get($request->getQueryParams(), 'id');
$actor = $request->getAttribute('actor'); $actor = $request->getAttribute('actor');
$data = array_get($request->getParsedBody(), 'data'); $data = array_get($request->getParsedBody(), 'data', []);
return $this->bus->dispatch( return $this->bus->dispatch(
new EditTag($id, $actor, $data) new EditTag($id, $actor, $data)