Skip to content

getting 'The HTTP status code "0" is not valid' exception #418

arashdalir opened this Issue Apr 3, 2013 · 2 comments

2 participants


Hi everyone!
I'm using FOSRestBundle to manage a profile edit form and am getting

The HTTP status code "0" is not valid

when trying to send redirection response to the client.

I've configured fos_rest as followed:

        default_priorities: ['json', "xml", html, '*/*']
            xml: true
            json: true
            html: true
            html: false
        failed_validation: HTTP_BAD_REQUEST
        default_engine: twig
        view_response_listener: 'force'
        serializer: jms_serializer.serializer
        version: ~
        groups: []

my respective action function is as followed:

public function partialEditAction(Request $request)
        $user = $this->authenticate();
        /** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */
        $dispatcher = $this->container->get('event_dispatcher');

        $event = new GetResponseUserEvent($user, $request);
        $dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_INITIALIZE, $event);

        if (null !== $event->getResponse()) {
            return $event->getResponse();

        $action = $request->get('part');

        $type = null;
        switch ($action){
        case 'personalInfo':
            $type = new PersonalInfoFormType();

        case 'email':
            $type = new EmailFormType();

        case 'password':
            $type = new PasswordFormType();

        $form = $this->createForm($type, $user);

        if ('POST' === $request->getMethod()) {

            if ($form->isValid()) {
                /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */
                $userManager = $this->container->get('fos_user.user_manager');

                //$event = new FormEvent($form, $request);
                //$dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_SUCCESS, $event);


                //if (null === $response = $event->getResponse())
                    $view = $this->routeRedirectView('fos_user_profile_show', array(), Codes::HTTP_SEE_OTHER);

                //$dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_COMPLETED, new FilterUserResponseEvent($user, $request, $response));

                return $this->handleView($view);

        $view = $this->view();
        $view->setData( array('form' => $form) );

        return $this->handleView($view);

as you can see, I'm trying to create a routeRedirectResponse with Codes::HTTP_SEE_OTHER as the status code and fos_user_profile_show as the route name. I'm trying to read the response later on the client side and according to the status code (204, 200, etc.) do an action. if the response is HTTP_SEE_OTHER, I'd be reading the location header value to find the redirection location and handle the request manually...
but FOSRestBundle keeps throwing the "InvalidArgumentException":

The HTTP status code "0" is not valid.

500 Internal Server Error - InvalidArgumentException

I traced the error to FOS\RestBundle\View\ViewHandler.php line: 274 :

        $code = isset($this->forceRedirects[$format])
            ? $this->forceRedirects[$format] : $this->getStatusCode($view, $content);


this line checks the value of my fos_rest config, find the force_redirects value for html format to be "false" and simply replaces my given status_code with a "false" value; which later on results in the http status code to be "0".

I'm not sure if this means that I have misconfigured the bundle or this could actually be a bug in the system. Could anyone please advise me on this matter?

FriendsOfSymfony member
lsmith77 commented Apr 4, 2013

maybe there is a bug in your routeRedirectView method?

FriendsOfSymfony member


@lsmith77 lsmith77 closed this Aug 14, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.