Skip to content

Commit

Permalink
Merge pull request #242 from FriendsOfCake/3.0-fix-api-exceptions
Browse files Browse the repository at this point in the history
Fix API exception rendering
  • Loading branch information
ADmad committed Jan 27, 2015
2 parents 7a12a35 + 21679c1 commit e342e58
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/Error/ExceptionRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function validation($error)
'_serialize' => ['code', 'url', 'message', 'errorCount', 'errors']
];
$this->controller->set($sets);
$this->_outputMessage('error400');
return $this->_outputMessage('error400');
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Listener/ApiListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Crud\Listener;

use Cake\Core\Configure;
use Cake\Error\ErrorHandler;
use Cake\Event\Event;
use Cake\Network\Exception\BadRequestException;
use Cake\Network\Request;
Expand Down Expand Up @@ -151,7 +152,8 @@ protected function _checkRequestMethods()
*/
public function registerExceptionHandler()
{
Configure::write('Error.exceptionRenderer', 'Crud\Error\ExceptionRenderer');
$exceptionRenderer = 'Crud\Error\ExceptionRenderer';
(new ErrorHandler(compact('exceptionRenderer') + (array)Configure::read('Error')))->register();
}

/**
Expand Down
39 changes: 0 additions & 39 deletions tests/TestCase/Listener/ApiListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1022,45 +1022,6 @@ public function testSetupDetectorsIntigration()
);
}

/**
* testRegisterExceptionHandler with Api request
*
* @return void
*/
public function testRegisterExceptionHandlerWithApi()
{
$listener = $this
->getMockBuilder('\Crud\Listener\ApiListener')
->setMethods(null)
->disableOriginalConstructor()
->getMock();

$listener->registerExceptionHandler();

$expected = 'Crud\Error\ExceptionRenderer';
$result = Configure::read('Error.exceptionRenderer');
$this->assertEquals($expected, $result);
}

/**
* testRegisterExceptionHandler without Api request
*
* @return void
*/
public function testRegisterExceptionHandlerWithoutApi()
{
$listener = $this
->getMockBuilder('\Crud\Listener\ApiListener')
->setMethods(null)
->disableOriginalConstructor()
->getMock();

$listener->registerExceptionHandler();

$expected = 'Crud\Error\ExceptionRenderer';
$result = Configure::read('Error.exceptionRenderer');
$this->assertEquals($expected, $result);
}
/**
* data provider for testCheckRequestMethods
*
Expand Down

0 comments on commit e342e58

Please sign in to comment.