Skip to content

Commit 284b46c

Browse files
committed
refactor(RenderUsing): Simplify exception handling logic
- Remove unnecessary try-catch block for cleaner flow - Replace with `rescue` function to streamline exception reporting - Maintain original exception handling behavior while improving readability
1 parent d47f22a commit 284b46c

File tree

2 files changed

+5
-26
lines changed

2 files changed

+5
-26
lines changed

composer-require-checker.json

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,6 @@
1515
"Foo.php"
1616
],
1717
"symbol-whitelist": [
18-
"array",
19-
"bool",
20-
"callable",
21-
"false",
22-
"float",
23-
"int",
24-
"null",
25-
"object",
26-
"parent",
27-
"self",
28-
"static",
29-
"string",
30-
"true",
31-
"void",
32-
3318
"dd",
3419
"dump",
3520
"make",

src/RenderUsings/RenderUsing.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,11 @@ abstract class RenderUsing
2525
*/
2626
public function __invoke(\Throwable $throwable, Request $request): ?JsonResponse
2727
{
28-
try {
29-
if ($this->when($request, $throwable)) {
30-
return ApiResponseFacade::exception($throwable);
31-
}
32-
} catch (\Throwable $throwable) {
33-
// If catch an exception, only report it,
34-
// and to let the default exception handler handle original exception.
35-
report($throwable);
36-
}
37-
38-
return null;
28+
// If catch an exception, only report it,
29+
// and to let the default exception handler handle original exception.
30+
return rescue(
31+
fn (): ?JsonResponse => $this->when($request, $throwable) ? ApiResponseFacade::exception($throwable) : null
32+
);
3933
}
4034

4135
abstract protected function when(Request $request, \Throwable $throwable): bool;

0 commit comments

Comments
 (0)