|
15 | 15 | use Illuminate\Http\Response; |
16 | 16 | use Illuminate\Session\TokenMismatchException; |
17 | 17 | use Illuminate\Support\Facades\Lang; |
18 | | -use Illuminate\Support\Facades\Log; |
19 | 18 | use Illuminate\Validation\ValidationException; |
20 | 19 | use Intervention\Image\Exception\NotSupportedException; |
21 | 20 | use JsonException; |
@@ -60,14 +59,36 @@ class Handler extends ExceptionHandler |
60 | 59 | public function report(Throwable $exception) |
61 | 60 | { |
62 | 61 | if ($this->shouldReport($exception)) { |
63 | | - if (class_exists(Log::class)) { |
64 | | - Log::error($exception); |
65 | | - } |
66 | | - |
67 | 62 | return parent::report($exception); |
68 | 63 | } |
69 | 64 | } |
70 | 65 |
|
| 66 | + /** |
| 67 | + * Report a caught exception, and rethrow in dev when the underlying |
| 68 | + * cause is a programmer-error \Error (TypeError, ArgumentCountError, |
| 69 | + * etc.) so it fails loud with a stack trace in dev instead of hiding behind |
| 70 | + * a friendly "something went wrong" flash. Plain \Exception (sub)types |
| 71 | + * (QueryException, ItemStillHasAssets, etc.) *always* report + return so |
| 72 | + * bulk operations can keep swallowing runtime-data failures per row. |
| 73 | + * |
| 74 | + * We should use this as a drop-in for `report($e)` inside the wide-net |
| 75 | + * catch (\Throwable $e) blocks in the bulk destroy / import paths. |
| 76 | + */ |
| 77 | + public static function reportOrRethrow(Throwable $e): void |
| 78 | + { |
| 79 | + // Both APP_DEBUG must be on AND the environment must |
| 80 | + // not be production before the raw \Error is allowed to |
| 81 | + // escape past the friendly user-facing error. |
| 82 | + if ( |
| 83 | + config('app.debug') |
| 84 | + && ! app()->environment('production') |
| 85 | + && $e instanceof \Error |
| 86 | + ) { |
| 87 | + throw $e; |
| 88 | + } |
| 89 | + report($e); |
| 90 | + } |
| 91 | + |
71 | 92 | /** |
72 | 93 | * Render an exception into an HTTP response. |
73 | 94 | * |
@@ -161,7 +182,7 @@ public function render($request, Throwable $e) |
161 | 182 | // This is traaaaash but it handles models that are not found while using route model binding :( |
162 | 183 | // The only alternative is to set that at *each* route, which is crazypants |
163 | 184 | if ($e instanceof ModelNotFoundException) { |
164 | | - $ids = method_exists($e, 'getIds') ? $e->getIds() : []; |
| 185 | + $ids = $e->getIds(); |
165 | 186 |
|
166 | 187 | if (in_array('bulkedit', $ids, true)) { |
167 | 188 | $error_array = session()->get('bulk_asset_errors'); |
@@ -198,7 +219,7 @@ public function render($request, Throwable $e) |
198 | 219 | // Normalize the space-separated derived name to underscore |
199 | 220 | // so compound class names (AssetModel -> "asset model" -> "asset_model") |
200 | 221 | // resolve to keys that actually exist in general.php. |
201 | | - $translationKey = 'general.' . str_replace(' ', '_', $model_name); |
| 222 | + $translationKey = 'general.'.str_replace(' ', '_', $model_name); |
202 | 223 | $translatedName = Lang::has($translationKey) ? trans($translationKey) : $model_name; |
203 | 224 |
|
204 | 225 | return redirect() |
|
0 commit comments