On a Symfony project, I would return sometime an access denied Exception (403 code). I am doing this through Ajax. But the Exception return a 302 code with the FOS Bundle login page in location.
I isolated the issue on a test function and a test ajax:
PHP
/**
* @Route("/test")
* @Method("POST")
*/
public function testAction() {
throw $this->createAccessDeniedException();
}
JS
$.post('/test');
This Ajax call return a 302 code and redirect to login page (in response)
How can I solve this "bug"?
EDIT
I add the security.yml
main:
pattern: ^/
anonymous: true
provider: main
form_login:
login_path: fos_user_security_login
check_path: fos_user_security_check
logout:
path: fos_user_security_logout
target: /
remember_me:
secret: %secret%
Thanks in advance