I am writing a middleware in laravel 5. I want to throw a forbidden exception with code 403 from middleware. My middleware function is given below:
use Exception;
public function handle($request, Closure $next)
{
if (!Auth::check()) {
throw new Exception("Access denied", 403);
}
return $next($request);
}
I am calling my middleware from controller and I am getting error message with code 500 but not 403. How can I resolve this?