Explorar el Código

Merge pull request #201 from stloyd/json_package_notfound

Throw error response if package was not found
Jordi Boggiano hace 12 años
padre
commit
4ffa04c65a
Se han modificado 1 ficheros con 4 adiciones y 0 borrados
  1. 4 0
      src/Packagist/WebBundle/Controller/WebController.php

+ 4 - 0
src/Packagist/WebBundle/Controller/WebController.php

@@ -286,6 +286,10 @@ class WebController extends Controller
                 ->getRepository('PackagistWebBundle:Package')
                 ->getFullPackageByName($name);
         } catch (NoResultException $e) {
+            if ('json' === $req->getRequestFormat()) {
+                return new JsonResponse(array('status' => 'error', 'message' => 'Package not found'), 404);
+            }
+
             return $this->redirect($this->generateUrl('search', array('q' => $name, 'reason' => 'package_not_found')));
         }