Skip to content

Commit 1a42f3e

Browse files
authored
Merge pull request #8041 from cakephp/custom-exception-renderer
Improve exception renderer overriding docs.
2 parents f42907f + eeed7e3 commit 1a42f3e

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

en/controllers/middleware.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,17 @@ called at the beginning of the request process, you can use the
7373

7474
namespace App;
7575

76+
use Cake\Core\Configure;
77+
use Cake\Error\Middleware\ErrorHandlerMiddleware;
7678
use Cake\Http\BaseApplication;
7779
use Cake\Http\MiddlewareQueue;
78-
use Cake\Error\Middleware\ErrorHandlerMiddleware;
7980

8081
class Application extends BaseApplication
8182
{
8283
public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue
8384
{
8485
// Bind the error handler into the middleware queue.
85-
$middlewareQueue->add(new ErrorHandlerMiddleware());
86+
$middlewareQueue->add(new ErrorHandlerMiddleware(Configure::read('Error'), $this));
8687

8788
// Add middleware by classname.
8889
// As of 4.5.0 classname middleware are optionally resolved

en/development/errors.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ a ``missingWidget()`` controller method, and CakePHP would use
225225

226226
class ErrorController extends AppController
227227
{
228-
protected function missingWidget(MissingWidgetException $error)
228+
protected function missingWidget(MissingWidgetException $exception)
229229
{
230230
// You can prepare additional template context or trap errors.
231231
}
@@ -265,11 +265,11 @@ error pages when this error is handled::
265265
}
266266
}
267267

268-
// In config/app.php
269-
'Error' => [
270-
'exceptionRenderer' => 'App\Error\AppExceptionRenderer',
271-
// ...
272-
],
268+
// In Application::middleware()
269+
$middlewareQueue->add(new ErrorHandlerMiddleware(
270+
['exceptionRenderer' => AppExceptionRenderer::class] + Configure::read('Error'),
271+
$this,
272+
));
273273
// ...
274274

275275
The above would handle our ``MissingWidgetException``,
@@ -315,11 +315,11 @@ override the ``_getController()`` method in your exception renderer::
315315
}
316316
}
317317

318-
// in config/app.php
319-
'Error' => [
320-
'exceptionRenderer' => 'App\Error\AppExceptionRenderer',
321-
// ...
322-
],
318+
// In Application::middleware()
319+
$middlewareQueue->add(new ErrorHandlerMiddleware(
320+
['exceptionRenderer' => AppExceptionRenderer::class] + Configure::read('Error'),
321+
$this,
322+
));
323323
// ...
324324

325325

0 commit comments

Comments
 (0)