Yii2, error occurs while throwing NotFoundException - php

I have a simple code that is running on beforeAction event of my application:
'on beforeAction' => function ($event) {
throw new \yii\web\NotFoundHttpException('The requested page does not exist.');
},
I expect it to simply show 404 page of my application, but it throws following error:
An Error occurred while handling another error:
exception 'yii\web\NotFoundHttpException' with message 'The requested page does not exist.' in /home/files/www/ucms/config/frontend/config.php:9
Stack trace:
0 [internal function]: {closure}(Object(yii\base\ActionEvent))
1 /home/files/www/ucms/vendor/yiisoft/yii2/base/Component.php(541): call_user_func(Object(Closure), Object(yii\base\ActionEvent))
2 /home/files/www/ucms/vendor/yiisoft/yii2/base/Module.php(607): yii\base\Component->trigger('beforeAction', Object(yii\base\ActionEvent))
3 /home/files/www/ucms/vendor/yiisoft/yii2/base/Controller.php(139): yii\base\Module->beforeAction(Object(yii\web\ErrorAction))
4 /home/files/www/ucms/vendor/yiisoft/yii2/base/Module.php(455): yii\base\Controller->runAction('error', Array)
5 /home/files/www/ucms/vendor/yiisoft/yii2/web/ErrorHandler.php(85): yii\base\Module->runAction('site/error')
6 /home/files/www/ucms/vendor/yiisoft/yii2/base/ErrorHandler.php(109): yii\web\ErrorHandler->renderException(Object(yii\web\NotFoundHttpException))
7 [internal function]: yii\base\ErrorHandler->handleException(Object(yii\web\NotFoundHttpException))
8 {main}
Previous exception:
exception 'yii\web\NotFoundHttpException' with message 'The requested page does not exist.' in /home/files/www/ucms/config/frontend/config.php:9
Stack trace:
0 [internal function]: {closure}(Object(yii\base\ActionEvent))
1 /home/files/www/ucms/vendor/yiisoft/yii2/base/Component.php(541): call_user_func(Object(Closure), Object(yii\base\ActionEvent))
2 /home/files/www/ucms/vendor/yiisoft/yii2/base/Module.php(607): yii\base\Component->trigger('beforeAction', Object(yii\base\ActionEvent))
3 /home/files/www/ucms/vendor/yiisoft/yii2/base/Controller.php(139): yii\base\Module->beforeAction(Object(yii\base\InlineAction))
4 /home/files/www/ucms/vendor/yiisoft/yii2/base/Module.php(455): yii\base\Controller->runAction('', Array)
5 /home/files/www/ucms/vendor/yiisoft/yii2/web/Application.php(84): yii\base\Module->runAction('', Array)
6 /home/files/www/ucms/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
7 /home/files/www/ucms/web/index.php(17): yii\base\Application->run()
8 {main}

Problem in ErrorHandler.php file on 85 line:
$result = Yii::$app->runAction($this->errorAction);
When ErrorHandler try run ErrorAction, NotFoundHttpException triggered again and ErrorHandler just show error message without render.
Solution:
public function beforeAction($action)
{
if(!$action instanceof \yii\web\ErrorAction) {
throw new \yii\web\NotFoundHttpException('The requested page does not exist.');
}
return parent::beforeAction($action);
}
Previous Answer:
On production server also need setup right environments settings in your index.php file:
defined('YII_DEBUG') or define('YII_DEBUG', false);
defined('YII_ENV') or define('YII_ENV', 'prod');

another fix which helped us was to add this environment variables in the index.php :
defined('YII_ENABLE_ERROR_HANDLER') or define('YII_ENABLE_ERROR_HANDLER', false);

Related

how to run class in components in yii2 advanced console?

yii2 advanced
I have created a Controller - console/components/OneController.php
//One
namespace console\controllers;
use Yii;
use yii\console\Controller;
Class OneController extends Controller{
public function actionIndex(){
echo 'one!';
return true;
}
}
//command in console:
php yii one
//result:
one!
its working!
I am creating my folder for my test controllers - components
I am creating my Controller - console/components/TwoController.php
//Two
namespace console\controllers;
use Yii;
use yii\console\Controller;
Class TwoController extends Controller{
public function actionIndex(){
echo 'two!';
return true;
}
}
console\config\main-local.php
'controllerMap' => [
'fixture' => [
'class' => 'yii\console\controllers\FixtureController',
'namespace' => 'common\fixtures',
],
'two' => [
'class' => 'yii\console\components\TwoController',//++
],
],
//command in console:
php yii two
its not working. How to run my Controller in my Folder?
Administrator#WIN-XXXXXXXXXXX c:\Administrator\OpenServer\OpenServer\domains\mysite.us
$ php yii two
An Error occurred while handling another error:
exception 'ReflectionException' with message 'Class yii\console\components\TwoController does not exist' in C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\di\Container.php:424
Stack trace:
#0 C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\di\Container.php(424): ReflectionClass->__construct('yii\\console\\com...')
#1 C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\di\Container.php(364): yii\di\Container->getDependencies('yii\\console\\com...')
#2 C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\di\Container.php(156): yii\di\Container->build('yii\\console\\com...', Array, Array)
#3 C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\BaseYii.php(344): yii\di\Container->get('yii\\console\\com...', Array, Array)
#4 C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\base\Module.php(578): yii\BaseYii::createObject(Array, Array)
#5 C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\console\UnknownCommandException.php(79): yii\base\Module->createController('test')
#6 C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\console\ErrorHandler.php(35): yii\console\UnknownCommandException->getSuggestedAlternatives()
#7 C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\base\ErrorHandler.php(111): yii\console\ErrorHandler->renderException(Object(yii\console\UnknownCommandException))
#8 [internal function]: yii\base\ErrorHandler->handleException(Object(yii\console\UnknownCommandException))
#9 {main}
Previous exception:
exception 'yii\base\InvalidRouteException' with message 'Unable to resolve the request "two".' in C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\base\Module.php:532
Stack trace:
#0 C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\console\Application.php(180): yii\base\Module->runAction('two', Array)
#1 C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\console\Application.php(147): yii\console\Application->runAction('two', Array)
#2 C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\base\Application.php(380): yii\console\Application->handleRequest(Object(yii\console\Request))
#3 C:\Administrator\OpenServer\OpenServer\domains\mysite.us\yii(27): yii\base\Application->run()
#4 {main}
Next exception 'yii\console\UnknownCommandException' with message 'Unknown command "two".' in C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\console\Application.php:183
Stack trace:
#0 C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\console\Application.php(147): yii\console\Application->runAction('two', Array)
#1 C:\Administrator\OpenServer\OpenServer\domains\mysite.us\vendor\yiisoft\yii2\base\Application.php(380): yii\console\Application->handleRequest(Object(yii\console\Request))
#2 C:\Administrator\OpenServer\OpenServer\domains\mysite.us\yii(27): yii\base\Application->run()
#3 {main}

how do flash message with Slim framework 3

I have the problem to use Slim/Flash/Messages, to do a flash message. I have this error
Fatal error:
Uncaught DI\NotFoundException: No entry or class found for 'Slim\Flash' in C:\laragon\www\cart\vendor\php-di\php-di\src\DI\Container.php:119
Stack trace:
#0 C:\laragon\www\cart\app\container.php(52): DI\Container->get('Slim\\Flash')
#1 [internal function]: DI\Definition\Source\DefinitionFile->{closure}(Object(DI\Container)) #2 C:\laragon\www\cart\vendor\php-di\invoker\src\Invoker.php(82): call_user_func_array(Object(Closure), Array)
#3 C:\laragon\www\cart\vendor\php-di\php-di\src\DI\Definition\Resolver\FactoryResolver.php(81): Invoker\Invoker->call(Object(Closure), Array)
#4 C:\laragon\www\cart\vendor\php-di\php-di\src\DI\Definition\Resolver\ResolverDispatcher.php(58): DI\Definition\Resolver\FactoryResolver->resolve(Object(DI\Definition\FactoryDefinition), Array)
#5 C:\laragon\www\cart\vendor\php-di\php-di\src\DI\Container.php(285): DI\Definition\Resolver\ResolverDispatcher->resolve(Object(DI\Definition\FactoryDefinition), Array)
#6 C:\laragon\www\cart\vendor\php-di\php-di\src\DI\Container.php(122): DI\Contai in C:\laragon\www\cart\vendor\php-di\php-di\src\DI\Container.php on line 119
In the bootstrap/app.php
$container->set('flash', function($container) {
return new \Slim\Flash\Messages($container);
});
in the container.php
Twig::class => function (ContainerInterface $c) {
$twig = Factory::getEngine();
$twig->addExtension(new TwigExtension(
$c->get('router'),
$c->get('request')->getUri()
));
$twig->getEnvironment()->addGlobal('basket', $c->get(Basket::class));
$twig->getEnvironment()->addGlobal('auth', $c->get(Auth::class));
$twig->getEnvironment()->addGlobal('user', $c->get(Customer::class));
$twig->getEnvironment()->addGlobal('flash', $c->get(Flash::class));
return $twig;
},
$twig->getEnvironment()->addGlobal('flash', $c->get(Flash::class)); means that you're looking for a key called Slim\Flash within the container, but you registered it with the key flash.
Therefore change:
$twig->getEnvironment()->addGlobal('flash', $c->get(Flash::class));
to
$twig->getEnvironment()->addGlobal('flash', $c->get('flash'));
Alternatively, you can use the fully qualified class name everywhere:
app.php:
use Slim\Flash\Messages as Flash;
$container->set(Flash::class, function($container) {
return new Flash($container);
});
and add this to the top of container.php:
use Slim\Flash\Messages as Flash;

Yii2 Access denied (ForbiddenHttpException) to backend controller

I installed new Yii advanced framework. Nginx server.
Below url is working fine:
http://yii/backend/web/index.php?r=site/index
I created new CRUD using GII and accessed:
http://yii/backend/web/index.php?r=user/index
It showing below error:
An Error occurred while handling another error:
exception 'yii\web\ForbiddenHttpException' with message 'You are not allowed to perform this action.' in /private/var/www/yii/advanced/vendor/yiisoft/yii2/filters/AccessControl.php:151
Stack trace:
#0 /private/var/www/yii/advanced/vendor/yiisoft/yii2/filters/AccessControl.php(134): yii\filters\AccessControl->denyAccess(Object(yii\web\User))
#1 /private/var/www/yii/advanced/vendor/yiisoft/yii2/base/ActionFilter.php(71): yii\filters\AccessControl->beforeAction(Object(yii\web\ErrorAction))
#2 [internal function]: yii\base\ActionFilter->beforeFilter(Object(yii\base\ActionEvent))
#3 /private/var/www/yii/advanced/vendor/yiisoft/yii2/base/Component.php(541): call_user_func(Array, Object(yii\base\ActionEvent))
#4 /private/var/www/yii/advanced/vendor/yiisoft/yii2/base/Controller.php(263): yii\base\Component->trigger('beforeAction', Object(yii\base\ActionEvent))
#5 /private/var/www/yii/advanced/vendor/yiisoft/yii2/web/Controller.php(108): yii\base\Controller->beforeAction(Object(yii\web\ErrorAction))
#6 /private/var/www/yii/advanced/vendor/yiisoft/yii2/base/Controller.php(149): yii\web\Controller->beforeAction(Object(yii\web\ErrorAction))
#7 /private/var/www/yii/advanced/vendor/yiisoft/yii2/base/Module.php(455): yii\base\Controller->runAction('error', Array)
#8 /private/var/www/yii/advanced/vendor/yiisoft/yii2/web/ErrorHandler.php(85): yii\base\Module->runAction('site/error')
#9 /private/var/www/yii/advanced/vendor/yiisoft/yii2/base/ErrorHandler.php(109): yii\web\ErrorHandler->renderException(Object(yii\web\NotFoundHttpException))
#10 [internal function]: yii\base\ErrorHandler->handleException(Object(yii\web\NotFoundHttpException))
#11 {main}
Previous exception:
exception 'yii\base\InvalidRouteException' with message 'Unable to resolve the request "user/index".' in /private/var/www/yii/advanced/vendor/yiisoft/yii2/base/Module.php:461
Stack trace:
#0 /private/var/www/yii/advanced/vendor/yiisoft/yii2/web/Application.php(84): yii\base\Module->runAction('user/index', Array)
#1 /private/var/www/yii/advanced/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
#2 /private/var/www/yii/advanced/backend/web/index.php(18): yii\base\Application->run()
#3 {main}
Next exception 'yii\web\NotFoundHttpException' with message 'Page not found.' in /private/var/www/yii/advanced/vendor/yiisoft/yii2/web/Application.php:96
Stack trace:
#0 /private/var/www/yii/advanced/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
#1 /private/var/www/yii/advanced/backend/web/index.php(18): yii\base\Application->run()
#2 {main}
Did i missed any configuration?
Yii2 isset AccessControl
public function behaviors()
{
return [
'access' => [
'class' => \yii\filters\AccessControl::className(),
'only' => ['create', 'update'],
'rules' => [
// deny all POST requests
[
'allow' => false,
'verbs' => ['POST']
],
// allow authenticated users
[
'allow' => true,
'roles' => ['#'],
],
// everything else is denied
],
],
];
}
exception 'yii\web\ForbiddenHttpException' with message 'You are not
allowed to perform this action.' in
/private/var/www/yii/advanced/vendor/yiisoft/yii2/filters/AccessControl.php:151
Here is yii2 code
/**
* Denies the access of the user.
* The default implementation will redirect the user to the login page if he is a guest;
* if the user is already logged, a 403 HTTP exception will be thrown.
* #param User $user the current user
* #throws ForbiddenHttpException if the user is already logged in.
*/
protected function denyAccess($user)
{
if ($user->getIsGuest()) {
$user->loginRequired();
} else {
throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
//this is 152 line
}
}
So I think its very clear that you need to login first, so go to http://yii/backend/web/index.php?r=user/login.
If dont have login user/login page then remove all behaviors section at the top of your UserController.
public function behaviors()
{
.
.
.
}

PHPUnit > How to test whether the correct type was passed to a method?

I have a method where I've set the type of first argument to be passed (array):
public function create(array $values, $options=array())
{
// set datetime columns
if(! isset($values['date_created']) or empty($values['date_created'])) {
$values['date_created'] = date("Y-m-d H:i:s");
}
if(! isset($values['date_updated']) or empty($values['date_updated'])) {
$values['date_updated'] = date("Y-m-d H:i:s");
}
return parent::create($values);
}
How do I test this using PHPUnit, it keeps throwing a fatal error which I guess is to be expected but it doesn't allow my script to run:
1) UserTableTest::testCreateMethodWithInvalidArguments
Failed asserting that exception of type "PHPUnit_Framework_Error" matches expected exception "InvalidArgumentException". Message was: "Argument 1 passed to app\models\UserTable::create() must be of the type array, string given, called in /var/www/phpdev/tests/models/UserTableMockTest.php on line 82 and defined" at
#0 /var/www/phpdev/app/models/UserTable.php(16): PHPUnit_Util_ErrorHandler::handleError(4096, 'Argument 1 pass...', '/var/www/phpdev...', 16, Array)
#1 /var/www/phpdev/tests/models/UserTableMockTest.php(82): app\models\UserTable->create('invalid argumen...')
#2 [internal function]: UserTableTest->testCreateMethodWithInvalidArguments()
#3 /var/www/phpdev/vendor/phpunit/phpunit/src/Framework/TestCase.php(962): ReflectionMethod->invokeArgs(Object(UserTableTest), Array)
#4 /var/www/phpdev/vendor/phpunit/phpunit/src/Framework/TestCase.php(826): PHPUnit_Framework_TestCase->runTest()
#5 /var/www/phpdev/vendor/phpunit/phpunit/src/Framework/TestResult.php(686): PHPUnit_Framework_TestCase->runBare()
#6 /var/www/phpdev/vendor/phpunit/phpunit/src/Framework/TestCase.php(760): PHPUnit_Framework_TestResult->run(Object(UserTableTest))
#7 /var/www/phpdev/vendor/phpunit/phpunit/src/Framework/TestSuite.php(699): PHPUnit_Framework_TestCase->run(Object(PHPUnit_Framework_TestResult))
#8 /var/www/phpdev/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(426): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#9 /var/www/phpdev/vendor/phpunit/phpunit/src/TextUI/Command.php(179): PHPUnit_TextUI_TestRunner->doRun(Object(PHPUnit_Framework_TestSuite), Array)
#10 /var/www/phpdev/vendor/phpunit/phpunit/src/TextUI/Command.php(132): PHPUnit_TextUI_Command->run(Array, true)
#11 /var/www/phpdev/vendor/phpunit/phpunit/phpunit(55): PHPUnit_TextUI_Command::main()
#12 {main}.
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
Should I instead remove the type hint and use is_array($values) to tell whether the correct type is passed then throw an exception? In PHPUnit I am expecting an exception is thrown anyway. By the way, below is my test:
/**
* #expectedException InvalidArgumentException
*/
public function testCreateMethodWithInvalidArguments()
{
// pass invalid argument, should be an array of values
$result = $this->userTable->create('invalid argument type');
}
PHPUnit just has to be made aware that you are expecting and exception so it can properly handle it and report upon it.
public function testExceptionHasRightMessage()
{
$this->setExpectedException(
'InvalidArgumentException', 'Right Message'
);
throw new InvalidArgumentException('Some Message', 10);
}
This was pulled from the example 2.11 at PHP Unit Documentation - Writing Unit Tests

Suppressing stack trace dump in Laravel log after App::abort(403)

I'm setting up a custom Acl for a Laravel 4.1 application.
My Routes.php file applies a before filter:
// Global authenticator
Route::filter('auth.vle', function()
{
return (new vleAuth)->authenticate();
});
// Authenticate all requests, except those to /login, /logout and /forgottenpassword
Route::whenRegex('/^(?!login|logout)(.*)$/', 'auth.vle');
and my vleAuth authenticate() method:
public function authenticate()
{
$this->acl = new vleAclService();
$endpoint = Route::current()->getAction()['controller'];
if (!$this->acl->validateEndpoint($endpoint)) {
Log::info('Routing', array( Route::current()->getUri(), $endpoint));
App::abort(403, 'Unauthorized action.');
}
}
When I access an endpoint which I am privileged to access, no problems; and when I access an endpoint that I'm not privileged to access, then I get a Forbidden - We're really sorry but you don't have the necessary permissions to access this page. message, so the authentication is working correctly as far as the "front-end" is concerned, and the routing information in the log bears this out.
However, whenever I try to access an endpoint that I'm not authenticated for, I also get a stack trace dumped in the Laravel log
[2014-06-12 15:00:16] production.INFO: ROUTE VALIDATION ["View_Reviews_ReviewsController#getIndex",false] []
[2014-06-12 15:00:16] production.ERROR: exception 'Symfony\Component\HttpKernel\Exception\HttpException' with message 'Unauthorized action.' in /home/vagrant/vleAppV2/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:875
Stack trace:
#0 /home/vagrant/vleAppV2/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(211): Illuminate\Foundation\Application->abort(403, 'Unauthorized ac...')
#1 /srv/api/laravel/app/controllers/vleAuth.php(104): Illuminate\Support\Facades\Facade::__callStatic('abort', Array)
#2 /srv/api/laravel/app/controllers/vleAuth.php(104): Illuminate\Support\Facades\App::abort(403, 'Unauthorized ac...')
#3 /srv/api/laravel/app/routes.php(20): vleAuth->authenticate()
#4 [internal function]: {closure}(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#5 /home/vagrant/vleAppV2/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(199): call_user_func_array(Object(Closure), Array)
#6 /home/vagrant/vleAppV2/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(154): Illuminate\Events\Dispatcher->fire('router.filter: ...', Array, true)
#7 /home/vagrant/vleAppV2/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1399): Illuminate\Events\Dispatcher->until('router.filter: ...', Array)
#8 /home/vagrant/vleAppV2/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1262): Illuminate\Routing\Router->callRouteFilter('auth.vle', Array, Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#9 /home/vagrant/vleAppV2/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1246): Illuminate\Routing\Router->callPatternFilters(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#10 /home/vagrant/vleAppV2/vendor/laravel/framework/src/Illuminate/Routing/Router.php(996): Illuminate\Routing\Router->callRouteBefore(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#11 /home/vagrant/vleAppV2/vendor/laravel/framework/src/Illuminate/Routing/Router.php(968): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#12 /home/vagrant/vleAppV2/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(738): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#13 /home/vagrant/vleAppV2/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(708): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
#14 /home/vagrant/vleAppV2/vendor/laravel/framework/src/Illuminate/Http/FrameGuard.php(38): Illuminate\Foundation\Application->handle(Object(Illuminate\Http\Request), 1, true)
#15 /home/vagrant/vleAppV2/vendor/laravel/framework/src/Illuminate/Session/Middleware.php(72): Illuminate\Http\FrameGuard->handle(Object(Illuminate\Http\Request), 1, true)
#16 /home/vagrant/vleAppV2/vendor/laravel/framework/src/Illuminate/Cookie/Queue.php(47): Illuminate\Session\Middleware->handle(Object(Illuminate\Http\Request), 1, true)
#17 /home/vagrant/vleAppV2/vendor/laravel/framework/src/Illuminate/Cookie/Guard.php(51): Illuminate\Cookie\Queue->handle(Object(Illuminate\Http\Request), 1, true)
#18 /home/vagrant/vleAppV2/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Illuminate\Cookie\Guard->handle(Object(Illuminate\Http\Request), 1, true)
#19 /home/vagrant/vleAppV2/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(606): Stack\StackedHttpKernel->handle(Object(Illuminate\Http\Request))
#20 /home/vagrant/vleAppV2/public/index.php(49): Illuminate\Foundation\Application->run()
#21 {main} [] []
I'm trying to suppress this because I don't want the logs filling up with stack traces; just the log info that I'm recording myself is all I actually need in the logs.
I've tried suppressing it by registering a new error handling function in app/global.php:
App::error(function(Exception $exception, $code)
{
// Don't log 403s
if ($exception instanceof Symfony\Component\HttpKernel\Exception\HttpException) {
return;
}
Log::error($exception);
});
but this doesn't seem to have any effect at all.
I've also tried wrapping the App:abort() in vleAuth.authenticate() within a try/catch block, but the Exception appears to have already been handled before this catch, so it hasn't helped either.
I've rerun composer dump-autoload to rebuild all appropriate autoloading, and have restarted the server just in case old scripts are being help in OpCache.
Can anybody tell me how I should be suppressing this stack trace?
The solution was in returning a response from the custom error handling function rather than a null return
App::error(function(Exception $exception, $code)
{
// Don't log 403s
if ($exception instanceof Symfony\Component\HttpKernel\Exception\HttpException) {
return Response::view('errors.403', array(), 403);
}
Log::error($exception);
});
This still displays the 403 page correctly, but overrides calling the default error handler that was generating the stack trace

Categories