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()
{
.
.
.
}
Related
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}
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);
I am getting a laravel error and I cannot figure out what is wrong with my code that would be causing the issue.
The issue is:
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
…/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php148
If anyone needs more information please let me know and I will supply.
Edit: Here is the stack trace
#0 /home/action/workspace/ssbb/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1049): Illuminate\Routing\RouteCollection->match(Object(Illuminate\Http\Request))
#1 /home/action/workspace/ssbb/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1017): Illuminate\Routing\Router->findRoute(Object(Illuminate\Http\Request))
#2 /home/action/workspace/ssbb/vendor/laravel/framework/src/Illuminate/Routing/Router.php(996): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#3 /home/action/workspace/ssbb/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(776): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#4 /home/action/workspace/ssbb/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(746): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
#5 /home/action/workspace/ssbb/vendor/laravel/framework/src/Illuminate/Session/Middleware.php(72): Illuminate\Foundation\Application->handle(Object(Illuminate\Http\Request), 1, true)
#6 /home/action/workspace/ssbb/vendor/laravel/framework/src/Illuminate/Cookie/Queue.php(47): Illuminate\Session\Middleware->handle(Object(Illuminate\Http\Request), 1, true)
#7 /home/action/workspace/ssbb/vendor/laravel/framework/src/Illuminate/Cookie/Guard.php(51): Illuminate\Cookie\Queue->handle(Object(Illuminate\Http\Request), 1, true)
#8 /home/action/workspace/ssbb/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Illuminate\Cookie\Guard->handle(Object(Illuminate\Http\Request), 1, true)
#9 /home/action/workspace/ssbb/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(642): Stack\StackedHttpKernel->handle(Object(Illuminate\Http\Request))
#10 /home/action/workspace/ssbb/public/index.php(49): Illuminate\Foundation\Application->run()
#11 {main} [] []
As I can't post in the comment section I am posting here
My friend you need to tell us which url you are trying to access,
As far as your route suggest it should be this in the browser localhost/laravel/-Your project name-/public/
As #jeemusu pointed out that this portion of your code is wrong
return View::make('site::index'), it should be ('site.index'),
There is a query constraint which accepts three parameters, you got only two there,
In this line
with('entry', Page::where('slug', 'welcome')->first()
please tell us what you are really trying to do
this was due to a URL not found so I just added the following code to my /app/start/global.php which then told me what URL it had trouble finding.
App::missing(function($e)
{
$url = Request::fullUrl();
Log::warning("404 for URL: $url");
return Response::make('404 not found', 404);
});
You can check everything using following code. Also filter 404 (NotFoundHttpException) error form your log file.
File : app/start/global.php
App::error(function(Exception $exception, $errorCode)
{
$requestUrl = Request::fullUrl();
$userAgent = Request::header('user-agent');
if($errorCode != 404){
Log::error('Exception', array(
'errorCode' => $errorCode,
'requestUrl' => $requestUrl,
'userAgent' => $userAgent,
'context' => $exception,
));
}
return Response::view('error-page-path.error-404', array(), 404);
// Here "error-404" is a blade view file in "error-page-path" directory
});
In my routes.php, I have this:
$apiSettings = [
'version' => 'v1',
'prefix' => 'api',
'protected' => true
];
Route::api($apiSettings, function() {
Route::get('venue', 'ApiDataController#venue');
});
The protected venue API route accesses a controller method. The controller method performs the Eloquent Query on a Venues model, and returns the response. This works perfectly.
The issue is in if I want to return an error - I am unsure how to. Here is the Venue Method:
public function venue(){
try {
//Some code that returns an exception
} catch(someexception $e) {
//How do I return the exception such that Dingo will parse it into a proper JSON response?
}
$response = Venue::with('address')->get();
return $response;
}
My attempted solution (in the try block):
try {
//some code that returns an exception
} catch(someexception $e) {
$response = array(
'message' => 'some random exception message'
);
return Response::json($response, 403);
}
I got the following error when I attempted to do that:
Argument 1 passed to Dingo\Api\Http\Response::makeFromExisting() must be an instance of Illuminate\Http\Response, instance of Illuminate\Http\JsonResponse given, called in /vagrant/www/planat-app/vendor/dingo/api/src/Routing/Router.php on line 165 and defined
Second Attempted Solution:
From Dingo's Returning Errors, docs, I tested what would happen if I returned one of the exceptions:
public function venue(){
throw new Symfony\Component\HttpKernel\Exception\ConflictHttpException('err);
}
However, instead of returning the error as a JSON response, a laravel error page comes up, with the following error displayed:
[internal function]: ApiDataController->venue()
#1 /vagrant/www/planat-app/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(231):
call_user_func_array(Array, Array)
#2 /vagrant/www/planat-app/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(93):
Illuminate\Routing\Controller->callAction('venue', Array)
#3 /vagrant/www/planat-app/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(62):
Illuminate\Routing\ControllerDispatcher->call(Object(ApiDataController),
Object(Illuminate\Routing\Route), 'venue')
#4 /vagrant/www/planat-app/vendor/laravel/framework/src/Illuminate/Routing/Router.php(930):
Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route),
Object(Dingo\Api\Http\InternalRequest), 'ApiDataControll...', 'venue')
#5 [internal function]: Illuminate\Routing\Router->Illuminate\Routing\{closure}()
#6 /vagrant/www/planat-app/vendor/laravel/framework/src/Illuminate/Routing/Route.php(105):
call_user_func_array(Object(Closure), Array)
#7 /vagrant/www/planat-app/vendor/laravel/framework/src/Illuminate/Routing/Router.php(996):
Illuminate\Routing\Route->run(Object(Dingo\Api\Http\InternalRequest))
#8 /vagrant/www/planat-app/vendor/laravel/framework/src/Illuminate/Routing/Router.php(964):
Illuminate\Routing\Router->dispatchToRoute(Object(Dingo\Api\Http\InternalRequest))
#9 /vagrant/www/planat-app/vendor/dingo/api/src/Routing/Router.php(147):
Illuminate\Routing\Router->dispatch(Object(Dingo\Api\Http\InternalRequest))
#10 /vagrant/www/planat-app/vendor/dingo/api/src/Dispatcher.php(337): Dingo\Api\Routing\Router->dispatch(Object(Dingo\Api\Http\InternalRequest))
#11 /vagrant/www/planat-app/vendor/dingo/api/src/Dispatcher.php(278): Dingo\Api\Dispatcher->dispatch(Object(Dingo\Api\Http\InternalRequest))
#12 /vagrant/www/planat-app/vendor/dingo/api/src/Dispatcher.php(213): Dingo\Api\Dispatcher->queueRequest('get', 'venue', Array)
#13 /vagrant/www/planat-app/app/routes.php(51): Dingo\Api\Dispatcher->get('venue')
#14 [internal function]: {closure}()
#15 /vagrant/www/planat-app/vendor/laravel/framework/src/Illuminate/Routing/Route.php(105):
call_user_func_array(Object(Closure), Array)
#16 /vagrant/www/planat-app/vendor/laravel/framework/src/Illuminate/Routing/Router.php(996):
Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))
#17 /vagrant/www/planat-app/vendor/laravel/framework/src/Illuminate/Routing/Router.php(964):
Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#18 /vagrant/www/planat-app/vendor/dingo/api/src/Routing/Router.php(147):
Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#19 /vagrant/www/planat-app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(738):
Dingo\Api\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#20 /vagrant/www/planat-app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(708):
Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
#21 /vagrant/www/planat-app/vendor/dingo/api/src/Http/Middleware/RateLimit.php(97):
Illuminate\Foundation\Application->handle(Object(Illuminate\Http\Request),
1, true)
#22 /vagrant/www/planat-app/vendor/dingo/api/src/Http/Middleware/Authentication.php(102):
Dingo\Api\Http\Middleware\RateLimit->handle(Object(Illuminate\Http\Request),
1, true)
#23 /vagrant/www/planat-app/vendor/laravel/framework/src/Illuminate/Session/Middleware.php(72):
Dingo\Api\Http\Middleware\Authentication->handle(Object(Illuminate\Http\Request),
1, true)
#24 /vagrant/www/planat-app/vendor/laravel/framework/src/Illuminate/Cookie/Queue.php(47):
Illuminate\Session\Middleware->handle(Object(Illuminate\Http\Request),
1, true)
#25 /vagrant/www/planat-app/vendor/laravel/framework/src/Illuminate/Cookie/Guard.php(51):
Illuminate\Cookie\Queue->handle(Object(Illuminate\Http\Request), 1,
true)
#26 /vagrant/www/planat-app/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23):
Illuminate\Cookie\Guard->handle(Object(Illuminate\Http\Request), 1,
true)
#27 /vagrant/www/planat-app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(606):
Stack\StackedHttpKernel->handle(Object(Illuminate\Http\Request))
#28 /vagrant/www/planat-app/public/index.php(49): Illuminate\Foundation\Application->run()
As you are building api, you can catch similar types of exception globally. For example, if a user tried to get a customer with an ID which doesn't exists, then you could do this.
Customer::findOrFail($id);
then you could catch all of this type exception in app/start/global.php like this.
App::error(function(ModelNotFoundException $modelNotFoundException){
$errorResponse = [
'errors' => 'Not found any resource',
'message' => $modelNotFoundException->getMessage()
];
return Response::json($errorResponse, 404); //404 = Not found
});
Reading from Dingo's Returning Errors docs, it says:
Instead of manually creating and returning an error response you can simply throw an exception and the package will handle the exception and return an appropriate response.
The following is a list of all the supported exceptions that you should throw when you encounter an error.
Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
Symfony\Component\HttpKernel\Exception\BadRequestHttpException
Symfony\Component\HttpKernel\Exception\ConflictHttpException
Symfony\Component\HttpKernel\Exception\GoneHttpException
Symfony\Component\HttpKernel\Exception\HttpException
Symfony\Component\HttpKernel\Exception\LengthRequiredHttpException
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
Symfony\Component\HttpKernel\Exception\PreconditionFailedHttpException
Symfony\Component\HttpKernel\Exception\PreconditionRequiredHttpException
Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException
Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException
Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException
It also supports some generic resource exceptions that you can pass validation errors onto as well:
Dingo\Api\Exception\DeleteResourceFailedException
Dingo\Api\Exception\ResourceException
Dingo\Api\Exception\StoreResourceFailedException
Dingo\Api\Exception\UpdateResourceFailedException
So in short, you need to throw one of the exceptions above that Dingo supports back to Dingo. For example:
try {
//Some code that returns an exception
} catch(SomeException $e) {
throw new Symfony\Component\HttpKernel\Exception\HttpException($e->getMessage);
}
Or in fact, if the exception thrown is one of the type above, or one that extends them, you can just remove your try/catch clause completely. The exception should be automatically thrown back to Dingo to handle it.
Please check this:
try {
//some code that returns an exception
} catch(\Exception $e) {
$response = array(
'message' => 'some random exception message'
);
return response()->json($response, 403);
}
Please check and let me know.
I'm trying to use Zend Db findBy() magic method, but it gives me this error:
Application error
Exception information:
Message: File "Game.php" does not exist or class "Game" was not found in the file
Stack trace:
#0 C:\Zend\ZendServer\share\ZendFramework\library\Zend\Db\Table\Row\Abstract.php(872): Zend_Db_Table_Row_Abstract->_getTableFromString('Game')
#1 C:\Zend\ZendServer\share\ZendFramework\library\Zend\Db\Table\Row\Abstract.php(1154): Zend_Db_Table_Row_Abstract->findDependentRowset('Game', NULL, NULL)
#2 C:\Zend\Apache2\htdocs\dev.gamenomad.com\application\controllers\GameController.php(125): Zend_Db_Table_Row_Abstract->__call('findGame', Array)
#3 C:\Zend\Apache2\htdocs\dev.gamenomad.com\application\controllers\GameController.php(125): Zend_Db_Table_Row->findGame()
#4 C:\Zend\ZendServer\share\ZendFramework\library\Zend\Controller\Action.php(516): GameController->platformAction()
#5 C:\Zend\ZendServer\share\ZendFramework\library\Zend\Controller\Dispatcher\Standard.php(295): Zend_Controller_Action->dispatch('platformAction')
#6 C:\Zend\ZendServer\share\ZendFramework\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#7 C:\Zend\ZendServer\share\ZendFramework\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
#8 C:\Zend\ZendServer\share\ZendFramework\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#9 C:\Zend\Apache2\htdocs\dev.gamenomad.com\public\index.php(26): Zend_Application->run()
#10 {main}
Request Parameters:
array (
'controller' => 'game',
'action' => 'platform',
'x' => '2',
'module' => 'default',
)
Seems like it doesn't detect Game.php even though it exists inside /application/models/DbTable/Game.php
Are there any rules or exceptions I am missing?
This is my code
public function platformAction()
{
// action body
$platform = intval($this->_request->getParam('x'));
$platformTable = new Application_Model_DbTable_Platform();
$xbox360 = $platformTable->find($platform)->current();
//$games = $xbox360->findDependentRowset('Application_Model_DbTable_Game');
$games = $xbox360->findGame();
if(isset($games))
{
if(count($games)>0)
{
foreach($games as $game)
{
echo "{$game->name}<br />";
}
}
}
}