Question

I am using FOSRestBundle.

I am using a GET request and I am expecting an 404 error message, but it is very long.

Here is the definition of the action() method:

/**
 * @Rest\View
 * @Rest\Get("/api/test/{id}",
 *      requirements={"id" = "\d+"},
 *      defaults={"id" = 1}
 * )
 */
public function getAction($id) {
    $repo = $this->getDoctrine()->
            getManager()->
            getRepository("MinnAdsAPIBundle:Test");
    $entity = $repo->find($id);
    if (!$entity) {
        throw $this->createNotFoundException('Unable to find test entity!');
    }
    return array('test' => $entity);
}

To check the request, I used this shell command: curl -i http://localhost/tuto/web/app_dev.php/api/test/16654

The result is:

HTTP/1.1 404 Not Found
Date: Fri, 11 Apr 2014 07:33:13 GMT
Server: Apache/2.2.22 (Ubuntu)
X-Powered-By: PHP/5.4.9-4ubuntu2.4
Set-Cookie: PHPSESSID=r5fjnf14fp0oou8ac8hu60vru7; path=/
Cache-Control: no-cache
Vary: Accept-Language
X-Debug-Token: 97fd81
Transfer-Encoding: chunked
Content-Type: application/json

[{"message":"Unable to find test entity!","class":"Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException","trace":[{"namespace":"","short_class":"","class":"","type":"","function":"","file":"\/home\/amine\/NetBeansProjects\/tuto\/vendor\/symfony\/symfony\/src\/Symfony\/Bundle\/FrameworkBundle\/Controller\/Controller.php","line":149,"args":[]},{"namespace":"Symfony\\Bundle\\FrameworkBundle\\Controller","short_class":"Controller","class":"Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller","type":"->","function":"createNotFoundException","file":"\/home\/amine\/NetBeansProjects\/tuto\/src\/Minn\/AdsAPIBundle\/Controller\/TestController.php","line":31,"args":[["string","Unable to find test entity!"]]},{"namespace":"Minn\\AdsAPIBundle\\Controller","short_class":"TestController","class":"Minn\\AdsAPIBundle\\Controller\\TestController","type":"->","function":"getAction","file":null,"line":null,"args":[["string","155"]]},{"namespace":"","short_class":"","class":"","type":"","function":"call_user_func_array","file":"\/home\/amine\/NetBeansProjects\/tuto\/app\/bootstrap.php.cache","line":2841,"args":[["array",[["object","Minn\\AdsAPIBundle\\Controller\\TestController"],["string","getAction"]]],["array",[["string","155"]]]]},{"namespace":"Symfony\\Component\\HttpKernel","short_class":"HttpKernel","class":"Symfony\\Component\\HttpKernel\\HttpKernel","type":"->","function":"handleRaw","file":"\/home\/amine\/NetBeansProjects\/tuto\/app\/bootstrap.php.cache","line":2815,"args":[["object","Symfony\\Component\\HttpFoundation\\Request"],["string","1"]]},{"namespace":"Symfony\\Component\\HttpKernel","short_class":"HttpKernel","class":"Symfony\\Component\\HttpKernel\\HttpKernel","type":"->","function":"handle","file":"\/home\/amine\/NetBeansProjects\/tuto\/app\/bootstrap.php.cache","line":2944,"args":[["object","Symfony\\Component\\HttpFoundation\\Request"],["string","1"],["boolean",true]]},{"namespace":"Symfony\\Component\\HttpKernel\\DependencyInjection","short_class":"ContainerAwareHttpKernel","class":"Symfony\\Component\\HttpKernel\\DependencyInjection\\ContainerAwareHttpKernel","type":"->","function":"handle","file":"\/home\/amine\/NetBeansProjects\/tuto\/app\/bootstrap.php.cache","line":2245,"args":[["object","Symfony\\Component\\HttpFoundation\\Request"],["string","1"],["boolean",true]]},{"namespace":"Symfony\\Component\\HttpKernel","short_class":"Kernel","class":"Symfony\\Component\\HttpKernel\\Kernel","type":"->","function":"handle","file":"\/home\/amine\/NetBeansProjects\/tuto\/web\/app_dev.php","line":29,"args":[["object","Symfony\\Component\\HttpFoundation\\Request"]]}]}]

The message I am expecting is:

HTTP/1.1 404 Not Found
Date: Fri, 11 Apr 2014 07:33:13 GMT
Server: Apache/2.2.22 (Ubuntu)
X-Powered-By: PHP/5.4.9-4ubuntu2.4
Set-Cookie: PHPSESSID=r5fjnf14fp0oou8ac8hu60vru7; path=/
Cache-Control: no-cache
Vary: Accept-Language
X-Debug-Token: 97fd81
Transfer-Encoding: chunked
Content-Type: application/json

{"message":"Unable to find test entity!"}

Is there any idea to achieve that?

thanks,

Was it helpful?

Solution

@amine put in your terminal this commande:

curl -i http://localhost/tutonew/web/api/test/16654

!!!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top