I am trying to trap TokenMismatchException in Laravel’s Handler.php
When I mimic a csrf token exception by temporarily removing the token from the form, the local dev version of my site shows me:
TokenMismatchException in VerifyCsrfToken.php line 68:
But when I change the render() function in Handler.php to look for the exception and handle the error, then it doesn’t work. For instance, if I replace the default code with the below for testing, and take the csrf token from the form, the system returns my 'this was not a token problem' message, and not the 'token problem' message.
public function render($request, Exception $exception)
{
if($exception instanceof TokenMismatchException) {
return('token problem');
}else{
return('this was not a token problem');
}
return parent::render($request, $exception);
}
So, with the default code Laravel seems to recognize the TokenMismatchException, but with my simple test code above, it doesn’t. Can you explain to me what’s going on here?