Skip to content

Commit

Permalink
fix(ui): "a.data.items is undefined" on first run
Browse files Browse the repository at this point in the history
When enabling the app for the very first time and opening the view, a
toast notification pops up with the following message:

> TypeError: a.data.items is undefined

This is caused by a silenced exception in lib/Controller/ItemController.
Due to it, not a single key is set in the $return array.

Responses returned from such a controller will be serialized as JSON.
However, the returned value is no longer a key-value array, but an
(empty) list and the serializer will convert it to `[]` instead of `{}`
what it should've been.

Now it will return a dummy response containing all the keys but
empty values, causing the serializer to return an object.

Signed-off-by: Vincent Neubauer <[email protected]>
  • Loading branch information
dallyger authored and Grotax committed May 30, 2024
1 parent f6b411a commit fd5aaa8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
9 changes: 7 additions & 2 deletions lib/Controller/ItemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,14 @@ public function index(
$return['items'] = $this->shareService->mapSharedByDisplayNames($items);

// this gets thrown if there are no items
// in that case just return an empty array
// in that case just return an empty response
} catch (ServiceException $ex) {
//NO-OP
return [
'items' => [],
'feeds' => [],
'newestItemId' => null,
'starred' => 0,
];
}

return $return;
Expand Down
9 changes: 8 additions & 1 deletion tests/Unit/Controller/ItemControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,13 @@ public function testItemsOffsetNotZero()

public function testGetItemsNoNewestItemsId()
{
$result = [
'items' => [],
'feeds' => [],
'newestItemId' => null,
'starred' => 0
];

$this->itemsApiExpects(2, ListType::FEED);

$this->itemService->expects($this->once())
Expand All @@ -463,7 +470,7 @@ public function testGetItemsNoNewestItemsId()
->will($this->throwException(new ServiceNotFoundException('')));

$response = $this->controller->index(ListType::FEED, 2, 3);
$this->assertEquals([], $response);
$this->assertEquals($result, $response);
}


Expand Down

0 comments on commit fd5aaa8

Please sign in to comment.