diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-11-20 16:25:13 +0100 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-11-20 16:25:13 +0100 |
commit | 56da73969ac49e400ade89248f87c643047221d6 (patch) | |
tree | f1364752f93175b27d91d671069891fc706a3ef7 | |
parent | 70584b42aaa75c2fe9adda5cf6c37ab63adcccb3 (diff) | |
download | wallabag-56da73969ac49e400ade89248f87c643047221d6.tar.gz wallabag-56da73969ac49e400ade89248f87c643047221d6.tar.zst wallabag-56da73969ac49e400ade89248f87c643047221d6.zip |
Return an explicit error if reload fail
-rw-r--r-- | src/Wallabag/ApiBundle/Controller/EntryRestController.php | 9 | ||||
-rw-r--r-- | 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 | |||
287 | 287 | ||
288 | /** | 288 | /** |
289 | * Reload an entry. | 289 | * Reload an entry. |
290 | * 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). | 290 | * 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). |
291 | * | 291 | * |
292 | * @ApiDoc( | 292 | * @ApiDoc( |
293 | * requirements={ | 293 | * requirements={ |
@@ -302,9 +302,6 @@ class EntryRestController extends WallabagRestController | |||
302 | $this->validateAuthentication(); | 302 | $this->validateAuthentication(); |
303 | $this->validateUserAccess($entry->getUser()->getId()); | 303 | $this->validateUserAccess($entry->getUser()->getId()); |
304 | 304 | ||
305 | // put default title in case of fetching content failed | ||
306 | $entry->setTitle('No title found'); | ||
307 | |||
308 | try { | 305 | try { |
309 | $entry = $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl()); | 306 | $entry = $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl()); |
310 | } catch (\Exception $e) { | 307 | } catch (\Exception $e) { |
@@ -313,12 +310,12 @@ class EntryRestController extends WallabagRestController | |||
313 | 'entry' => $entry, | 310 | 'entry' => $entry, |
314 | ]); | 311 | ]); |
315 | 312 | ||
316 | return new JsonResponse([], 304); | 313 | return new JsonResponse(['error' => 'Error while trying to fetch content'], 400); |
317 | } | 314 | } |
318 | 315 | ||
319 | // if refreshing entry failed, don't save it | 316 | // if refreshing entry failed, don't save it |
320 | if ($this->getParameter('wallabag_core.fetching_error_message') === $entry->getContent()) { | 317 | if ($this->getParameter('wallabag_core.fetching_error_message') === $entry->getContent()) { |
321 | return new JsonResponse([], 304); | 318 | return new JsonResponse(['error' => 'Error while trying to extract content'], 400); |
322 | } | 319 | } |
323 | 320 | ||
324 | $em = $this->getDoctrine()->getManager(); | 321 | $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 | |||
690 | } | 690 | } |
691 | 691 | ||
692 | $this->client->request('PATCH', '/api/entries/'.$entry->getId().'/reload.json'); | 692 | $this->client->request('PATCH', '/api/entries/'.$entry->getId().'/reload.json'); |
693 | $this->assertEquals(304, $this->client->getResponse()->getStatusCode()); | 693 | $this->assertEquals(400, $this->client->getResponse()->getStatusCode()); |
694 | |||
695 | $this->assertContains('Error while trying to extract content', $this->client->getResponse()->getContent()); | ||
696 | |||
697 | $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); | ||
694 | } | 698 | } |
695 | 699 | ||
696 | public function testReloadEntry() | 700 | public function testReloadEntry() |