@@ -106,7 +106,7 @@ public function report(Exception $e)
106
106
try {
107
107
$ logger = $ this ->container ->make (LoggerInterface::class);
108
108
} catch (Exception $ ex ) {
109
- throw $ e ; // throw the original exception
109
+ throw $ e ;
110
110
}
111
111
112
112
$ logger ->error (
@@ -248,14 +248,9 @@ protected function convertValidationExceptionToResponse(ValidationException $e,
248
248
*/
249
249
protected function invalid ($ request , ValidationException $ exception )
250
250
{
251
- $ url = $ exception ->redirectTo ?? url ()->previous ();
252
-
253
- return redirect ($ url )
254
- ->withInput ($ request ->except ($ this ->dontFlash ))
255
- ->withErrors (
256
- $ exception ->errors (),
257
- $ exception ->errorBag
258
- );
251
+ return redirect ($ exception ->redirectTo ?? url ()->previous ())
252
+ ->withInput ($ request ->except ($ this ->dontFlash ))
253
+ ->withErrors ($ exception ->errors (), $ exception ->errorBag );
259
254
}
260
255
261
256
/**
@@ -283,9 +278,7 @@ protected function invalidJson($request, ValidationException $exception)
283
278
protected function prepareResponse ($ request , Exception $ e )
284
279
{
285
280
if (! $ this ->isHttpException ($ e ) && config ('app.debug ' )) {
286
- return $ this ->toIlluminateResponse (
287
- $ this ->convertExceptionToResponse ($ e ), $ e
288
- );
281
+ return $ this ->toIlluminateResponse ($ this ->convertExceptionToResponse ($ e ), $ e );
289
282
}
290
283
291
284
if (! $ this ->isHttpException ($ e )) {
@@ -305,21 +298,28 @@ protected function prepareResponse($request, Exception $e)
305
298
*/
306
299
protected function convertExceptionToResponse (Exception $ e )
307
300
{
308
- $ headers = $ this ->isHttpException ($ e ) ? $ e ->getHeaders () : [];
309
-
310
- $ statusCode = $ this ->isHttpException ($ e ) ? $ e ->getStatusCode () : 500 ;
301
+ return SymfonyResponse::create (
302
+ $ this ->renderExceptionContent ($ e ),
303
+ $ this ->isHttpException ($ e ) ? $ e ->getStatusCode () : 500 ,
304
+ $ this ->isHttpException ($ e ) ? $ e ->getHeaders () : []
305
+ );
306
+ }
311
307
308
+ /**
309
+ * Get the response content for the given exception.
310
+ *
311
+ * @param \Exception $e
312
+ * @return string
313
+ */
314
+ protected function renderExceptionContent (Exception $ e )
315
+ {
312
316
try {
313
- $ content = config ('app.debug ' ) && class_exists (Whoops::class)
314
- ? $ this ->renderExceptionWithWhoops ($ e )
315
- : $ this ->renderExceptionWithSymfony ($ e , config ('app.debug ' ));
317
+ return config ('app.debug ' ) && class_exists (Whoops::class)
318
+ ? $ this ->renderExceptionWithWhoops ($ e )
319
+ : $ this ->renderExceptionWithSymfony ($ e , config ('app.debug ' ));
316
320
} catch (Exception $ e ) {
317
- $ content = $ content ?? $ this ->renderExceptionWithSymfony ($ e , config ('app.debug ' ));
321
+ return $ this ->renderExceptionWithSymfony ($ e , config ('app.debug ' ));
318
322
}
319
-
320
- return SymfonyResponse::create (
321
- $ content , $ statusCode , $ headers
322
- );
323
323
}
324
324
325
325
/**
@@ -339,6 +339,16 @@ protected function renderExceptionWithWhoops(Exception $e)
339
339
})->handleException ($ e );
340
340
}
341
341
342
+ /**
343
+ * Get the Whoops handler for the application.
344
+ *
345
+ * @return \Whoops\Handler\Handler
346
+ */
347
+ protected function whoopsHandler ()
348
+ {
349
+ return (new WhoopsHandler )->forDebug ();
350
+ }
351
+
342
352
/**
343
353
* Render an exception to a string using Symfony.
344
354
*
@@ -354,58 +364,36 @@ protected function renderExceptionWithSymfony(Exception $e, $debug)
354
364
}
355
365
356
366
/**
357
- * Get the Whoops handler for the application .
367
+ * Render the given HttpException .
358
368
*
359
- * @return \Whoops\Handler\Handler
369
+ * @param \Symfony\Component\HttpKernel\Exception\HttpException $e
370
+ * @return \Symfony\Component\HttpFoundation\Response
360
371
*/
361
- protected function whoopsHandler ( )
372
+ protected function renderHttpException ( HttpException $ e )
362
373
{
363
- return tap (new PrettyPageHandler , function ($ handler ) {
364
- $ files = new Filesystem ;
374
+ $ this ->registerErrorViewPaths ();
365
375
366
- $ handler ->handleUnconditionally (true );
367
-
368
- foreach (config ('app.debug_blacklist ' , []) as $ key => $ secrets ) {
369
- foreach ($ secrets as $ secret ) {
370
- $ handler ->blacklist ($ key , $ secret );
371
- }
372
- }
373
-
374
- if (config ('app.editor ' , false )) {
375
- $ handler ->setEditor (config ('app.editor ' ));
376
- }
376
+ if (view ()->exists ($ view = "errors:: {$ e ->getStatusCode ()}" )) {
377
+ return response ()->view ($ view , [
378
+ 'exception ' => $ e , 'errors ' => new ViewErrorBag ,
379
+ ], $ e ->getStatusCode (), $ e ->getHeaders ());
380
+ }
377
381
378
- $ handler ->setApplicationPaths (
379
- array_flip (Arr::except (
380
- array_flip ($ files ->directories (base_path ())), [base_path ('vendor ' )]
381
- ))
382
- );
383
- });
382
+ return $ this ->convertExceptionToResponse ($ e );
384
383
}
385
384
386
385
/**
387
- * Render the given HttpException .
386
+ * Register the error template hint paths .
388
387
*
389
- * @param \Symfony\Component\HttpKernel\Exception\HttpException $e
390
- * @return \Symfony\Component\HttpFoundation\Response
388
+ * @return void
391
389
*/
392
- protected function renderHttpException ( HttpException $ e )
390
+ protected function registerErrorViewPaths ( )
393
391
{
394
- $ status = $ e ->getStatusCode ();
395
-
396
392
$ paths = collect (config ('view.paths ' ));
397
393
398
394
view ()->replaceNamespace ('errors ' , $ paths ->map (function ($ path ) {
399
395
return "{$ path }/errors " ;
400
396
})->push (__DIR__ .'/views ' )->all ());
401
-
402
- if (view ()->exists ($ view = "errors:: {$ status }" )) {
403
- return response ()->view ($ view , [
404
- 'exception ' => $ e , 'errors ' => new ViewErrorBag ,
405
- ], $ status , $ e ->getHeaders ());
406
- }
407
-
408
- return $ this ->convertExceptionToResponse ($ e );
409
397
}
410
398
411
399
/**
@@ -439,12 +427,10 @@ protected function toIlluminateResponse($response, Exception $e)
439
427
*/
440
428
protected function prepareJsonResponse ($ request , Exception $ e )
441
429
{
442
- $ status = $ this ->isHttpException ($ e ) ? $ e ->getStatusCode () : 500 ;
443
-
444
- $ headers = $ this ->isHttpException ($ e ) ? $ e ->getHeaders () : [];
445
-
446
430
return new JsonResponse (
447
- $ this ->convertExceptionToArray ($ e ), $ status , $ headers ,
431
+ $ this ->convertExceptionToArray ($ e ),
432
+ $ this ->isHttpException ($ e ) ? $ e ->getStatusCode () : 500 ,
433
+ $ this ->isHttpException ($ e ) ? $ e ->getHeaders () : [],
448
434
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
449
435
);
450
436
}
0 commit comments