From 56da73969ac49e400ade89248f87c643047221d6 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 20 Nov 2016 16:25:13 +0100 Subject: Return an explicit error if reload fail --- src/Wallabag/ApiBundle/Controller/EntryRestController.php | 9 +++------ tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 6 +++++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php index 7b7d94bf..1a726b6e 100644 --- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php +++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php @@ -287,7 +287,7 @@ class EntryRestController extends WallabagRestController /** * Reload an entry. - * An empty response with HTTP Status 304 will be send if we weren't able to update the content (because it hasn't changed or we got an error). + * A response with HTTP Status 400 will be return if we weren't able to update the content (because it hasn't changed or we got an error). * * @ApiDoc( * requirements={ @@ -302,9 +302,6 @@ class EntryRestController extends WallabagRestController $this->validateAuthentication(); $this->validateUserAccess($entry->getUser()->getId()); - // put default title in case of fetching content failed - $entry->setTitle('No title found'); - try { $entry = $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl()); } catch (\Exception $e) { @@ -313,12 +310,12 @@ class EntryRestController extends WallabagRestController 'entry' => $entry, ]); - return new JsonResponse([], 304); + return new JsonResponse(['error' => 'Error while trying to fetch content'], 400); } // if refreshing entry failed, don't save it if ($this->getParameter('wallabag_core.fetching_error_message') === $entry->getContent()) { - return new JsonResponse([], 304); + return new JsonResponse(['error' => 'Error while trying to extract content'], 400); } $em = $this->getDoctrine()->getManager(); diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 409a8291..432ce7d8 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -690,7 +690,11 @@ class EntryRestControllerTest extends WallabagApiTestCase } $this->client->request('PATCH', '/api/entries/'.$entry->getId().'/reload.json'); - $this->assertEquals(304, $this->client->getResponse()->getStatusCode()); + $this->assertEquals(400, $this->client->getResponse()->getStatusCode()); + + $this->assertContains('Error while trying to extract content', $this->client->getResponse()->getContent()); + + $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); } public function testReloadEntry() -- cgit v1.2.3