forked from NetCommons3/NetCommons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYAExceptionRenderer.php
More file actions
104 lines (100 loc) · 3.51 KB
/
YAExceptionRenderer.php
File metadata and controls
104 lines (100 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
/**
* Exception Renderer
*
* Provides Exception rendering features. Which allow exceptions to be rendered
* as HTML pages.
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since CakePHP(tm) v 2.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('Sanitize', 'Utility');
App::uses('Router', 'Routing');
App::uses('CakeResponse', 'Network');
App::uses('Controller', 'Controller');
App::uses('Error', 'ExceptionRenderer');
/**
* Exception Renderer.
*
* Captures and handles all unhandled exceptions. Displays helpful framework errors when debug > 1.
* When debug < 1 a CakeException will render 404 or 500 errors. If an uncaught exception is thrown
* and it is a type that ExceptionHandler does not know about it will be treated as a 500 error.
*
* ### Implementing application specific exception rendering
*
* You can implement application specific exception handling in one of a few ways:
*
* - Create a AppController::appError();
* - Create a subclass of YAExceptionRenderer and configure it to be the `Exception.renderer`
*
* #### Using AppController::appError();
*
* This controller method is called instead of the default exception handling. It receives the
* thrown exception as its only argument. You should implement your error handling in that method.
*
* #### Using a subclass of YAExceptionRenderer
*
* Using a subclass of YAExceptionRenderer gives you full control over how Exceptions are rendered, you
* can configure your class in your core.php, with `Configure::write('Exception.renderer', 'MyClass');`
* You should place any custom exception renderers in `app/Lib/Error`.
*
* @package NetCommons\NetCommons\Error
*/
class YAExceptionRenderer extends ExceptionRenderer {
/**
* Convenience method to display a 400 series page.
*
* @param Exception $error Exception
* @return void
*/
public function error400($error) {
$message = $error->getMessage();
if (!Configure::read('debug') && $error instanceof CakeException) {
$message = __d('cake', 'Not Found');
}
$url = $this->controller->request->here();
$this->controller->response->statusCode($error->getCode());
$this->controller->set(array(
'code' => $error->getCode(),
'name' => h($message),
'message' => h($message),
'url' => h($url),
'error' => $error,
'_serialize' => array('name', 'message', 'url', 'code')
));
$this->_outputMessage('error400');
}
/**
* Convenience method to display a 500 page.
*
* @param Exception $error Exception
* @return void
*/
public function error500($error) {
$message = $error->getMessage();
if (!Configure::read('debug')) {
$message = __d('cake', 'An Internal Error Has Occurred.');
}
$url = $this->controller->request->here();
$code = ($error->getCode() > 500 && $error->getCode() < 506) ? $error->getCode() : 500;
$this->controller->response->statusCode($code);
$this->controller->set(array(
'code' => $error->getCode(),
'name' => h($message),
'message' => h($message),
'url' => h($url),
'error' => $error,
'_serialize' => array('name', 'message', 'url', 'code')
));
$this->_outputMessage('error500');
}
}