]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/ApiBundle/Controller/EntryRestController.php
Create a new entry via API even when its content can't be retrieved
[github/wallabag/wallabag.git] / src / Wallabag / ApiBundle / Controller / EntryRestController.php
index 1a726b6edbcc776aa0ba2cb0f57ea862574732f1..e9e1aca3b2c2d6ea2f08453cc615db659aee1b33 100644 (file)
@@ -199,10 +199,19 @@ class EntryRestController extends WallabagRestController
         $entry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($url, $this->getUser()->getId());
 
         if (false === $entry) {
-            $entry = $this->get('wallabag_core.content_proxy')->updateEntry(
-                new Entry($this->getUser()),
-                $url
-            );
+            $entry = new Entry($this->getUser());
+            try {
+                $entry = $this->get('wallabag_core.content_proxy')->updateEntry(
+                    $entry,
+                    $url
+                );
+            } catch (\Exception $e) {
+                $this->get('logger')->error('Error while saving an entry', [
+                    'exception' => $e,
+                    'entry' => $entry,
+                ]);
+                $entry->setUrl($url);
+            }
         }
 
         if (!is_null($title)) {
@@ -287,7 +296,7 @@ class EntryRestController extends WallabagRestController
 
     /**
      * Reload an entry.
-     * 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).
+     * 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).
      *
      * @ApiDoc(
      *      requirements={
@@ -310,12 +319,12 @@ class EntryRestController extends WallabagRestController
                 'entry' => $entry,
             ]);
 
-            return new JsonResponse(['error' => 'Error while trying to fetch content'], 400);
+            return new JsonResponse([], 304);
         }
 
         // if refreshing entry failed, don't save it
         if ($this->getParameter('wallabag_core.fetching_error_message') === $entry->getContent()) {
-            return new JsonResponse(['error' => 'Error while trying to extract content'], 400);
+            return new JsonResponse([], 304);
         }
 
         $em = $this->getDoctrine()->getManager();