Better error handling.
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 27 Jun 2018 21:53:19 +0000 (23:53 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 27 Jun 2018 21:53:19 +0000 (23:53 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
config/config.yaml
src/Controller/PersonController.php

index 6aab19c0dd4af0367c670bf1dc146621e69b05fe..1bb645b20215b9e5be2c9598d1e0bbf05c47072b 100644 (file)
@@ -14,6 +14,8 @@ fos_rest:
     format_listener:
         rules:
             - { path: '^/api', priorities: ['json'], fallback_format: 'json' }
+    body_listener:
+        enabled: true
     versioning:
         enabled: true
         resolvers:
index 5dd8f2322cafe7cb4e0ef3fbb662be26466db59d..18f4a3ed7777e36c454a9b8d370058e1f4554c7b 100644 (file)
@@ -61,7 +61,7 @@ class PersonController extends Controller
         $person = $em->getRepository('App:Person')->find($request->get('id'));
 
         if (empty($person)) {
-            return new JsonResponse(['message' => 'Person not found'], Response::HTTP_NOT_FOUND);
+            return View::create(['message' => 'Person not found'], Response::HTTP_NOT_FOUND);
         }
 
         $person->setFirstName($request->get('firstname'));
@@ -114,7 +114,7 @@ class PersonController extends Controller
         $person = $em->getRepository('App:Person')->find($request->get('id'));
 
         if (empty($person)) {
-            return new JsonResponse(['message' => 'Person not found'], Response::HTTP_NOT_FOUND);
+            return View::create(['message' => 'Person not found'], Response::HTTP_NOT_FOUND);
         }
 
         $view = View::create($person);
@@ -137,7 +137,7 @@ class PersonController extends Controller
         $person = $em->getRepository('App:Person')->find($request->get('email'));
 
         if (empty($person)) {
-            return new JsonResponse(['message' => 'Person not found'], Response::HTTP_NOT_FOUND);
+            return View::create(['message' => 'Person not found'], Response::HTTP_NOT_FOUND);
         }
 
         $view = View::create($person);
@@ -160,7 +160,7 @@ class PersonController extends Controller
         $person = $em->getRepository('App:Person')->find($request->get('id'));
 
         if (empty($person)) {
-            return new JsonResponse(['message' => 'Person not found'], Response::HTTP_NOT_FOUND);
+            return View::create(['message' => 'Person not found'], Response::HTTP_NOT_FOUND);
         }
 
         $view = View::create($person->getFriends());
@@ -183,7 +183,7 @@ class PersonController extends Controller
         $person = $em->getRepository('App:Person')->find($request->get('email'));
 
         if (empty($person)) {
-            return new JsonResponse(['message' => 'Person not found'], Response::HTTP_NOT_FOUND);
+            return View::create(['message' => 'Person not found'], Response::HTTP_NOT_FOUND);
         }
 
         $view = View::create($person->getFriends());