cakephp 2.5.1: catching misspelled function calls -


i have api wirtten , gave out instructions how it. example test login can call /api/login

now see in logs, keeps calling /api/login , gets error 500.

is there somehow way, catch such errors when calling /api/ controller functions? in case, send response error. wrong function call. not want send in general when error 500 happens. when /api/ related.

the error gets reported belongs fact calling in appcontroller::beforefilter() function

$this->api->check($username) 

and error when debug=2

call member function check() on non-object  

when call /api/login/ functions works perfect.

i forward tips! thanks!

the problem facing isn't casing of action (in php method names case insensitive), casing of controller. won't find apicontroller , therefore throw missing controller exception. appcontroller being invoked being extended cakeerrorcontroller used on errors.

i can assume $this->api refers model, , since actual controller cakeerrorcontroller, model of course isn't being loaded, hence non-object error.

there various ways solve problem, i'd hook in dispatcher.beforedispatch event , throw exception or define appropriate response if necessary, this:

// app/config/bootstrap.php  app::uses('cakeevent', 'event'); app::uses('cakeeventmanager', 'event');  cakeeventmanager::instance()->attach(     function(cakeevent $event) {         $controller = $event->data['request']->params['controller'];         $action = $event->data['request']->params['action'];          if(strtolower($controller) === 'api') {             $response = $event->data['response'];              if($controller !== 'api') {                 $response->statuscode('403');                 $response->body('invalid controller message');                 return $response;             }              if(strtolower($action) !== $action) {                 $response->statuscode('403');                 $response->body('invalid action method');                 return $response;             }         }     },     'dispatcher.beforedispatch',     array('priority' => 11) ); 

this enforce using lowercase controller , action in case api controller being targeted.

however mentioned, method names case insensitive, forcing lowercase actions isn't necessary technical point of view. anyways, it's example...


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -