Browse Source

Merge pull request #201 from stloyd/json_package_notfound

Throw error response if package was not found
Jordi Boggiano 12 years ago
parent
commit
4ffa04c65a
1 changed files with 4 additions and 0 deletions
  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')));
         }