@@ -180,8 +180,7 @@ public function requireAuth($actions)
180
180
*
181
181
* @param \Cake\Controller\Controller $controller Instantiating controller
182
182
* @param string $error Error method
183
- * @param \Cake\Controller\Exception\SecurityException $exception Additional debug info describing the cause,
184
- * debug mode only
183
+ * @param \Cake\Controller\Exception\SecurityException $exception Additional debug info describing the cause
185
184
* @return mixed If specified, controller blackHoleCallback's response, or no return otherwise
186
185
* @see \Cake\Controller\Component\SecurityComponent::$blackHoleCallback
187
186
* @link http://book.cakephp.org/3.0/en/controllers/components/security.html#handling-blackhole-callbacks
@@ -190,14 +189,30 @@ public function requireAuth($actions)
190
189
public function blackHole (Controller $ controller , $ error = '' , SecurityException $ exception = null )
191
190
{
192
191
if (!$ this ->_config ['blackHoleCallback ' ]) {
193
- if (Configure::read ('debug ' ) && $ exception !== null ) {
194
- throw $ exception ;
195
- }
196
- throw new BadRequestException ('The request has been black-holed ' );
192
+ $ this ->_throwException ($ exception );
197
193
}
198
194
return $ this ->_callback ($ controller , $ this ->_config ['blackHoleCallback ' ], [$ error , $ exception ]);
199
195
}
200
196
197
+ /**
198
+ * Check debug status and throw an Exception based on the existing one
199
+ *
200
+ * @param \Cake\Controller\Exception\SecurityException $exception Additional debug info describing the cause
201
+ * @throws \Cake\Network\Exception\BadRequestException
202
+ */
203
+ protected function _throwException ($ exception = null )
204
+ {
205
+ $ defaultMessage = 'The request has been black-holed ' ;
206
+ if ($ exception !== null ) {
207
+ if (!Configure::read ('debug ' )) {
208
+ $ exception ->setReason ($ exception ->getMessage ());
209
+ $ exception ->setMessage ($ defaultMessage );
210
+ }
211
+ throw $ exception ;
212
+ }
213
+ throw new BadRequestException ($ defaultMessage );
214
+ }
215
+
201
216
/**
202
217
* Sets the actions that require a $method HTTP request, or empty for all actions
203
218
*
@@ -323,7 +338,7 @@ protected function _validatePost(Controller $controller)
323
338
*
324
339
* @param \Cake\Controller\Controller $controller Instantiating controller
325
340
* @throws \Cake\Controller\Exception\SecurityException
326
- * @return String fields token
341
+ * @return string fields token
327
342
*/
328
343
protected function _validToken (Controller $ controller )
329
344
{
0 commit comments