Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
82.35% |
14 / 17 |
|
40.00% |
2 / 5 |
CRAP | |
0.00% |
0 / 1 |
| Handler | |
82.35% |
14 / 17 |
|
40.00% |
2 / 5 |
10.55 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| report | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| shouldReport | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| renderForConsole | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| render | |
91.67% |
11 / 12 |
|
0.00% |
0 / 1 |
6.02 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Apie\LaravelApie\ErrorHandler; |
| 4 | |
| 5 | use Apie\Common\IntegrationTestLogger; |
| 6 | use Apie\Core\Exceptions\ApieException; |
| 7 | use Illuminate\Contracts\Container\Container; |
| 8 | use Illuminate\Contracts\Debug\ExceptionHandler; |
| 9 | use Illuminate\Foundation\Exceptions\Handler as ExceptionsHandler; |
| 10 | use Illuminate\Http\Response as HttpResponse; |
| 11 | use Symfony\Component\HttpFoundation\Response; |
| 12 | use Throwable; |
| 13 | |
| 14 | class Handler extends ExceptionsHandler |
| 15 | { |
| 16 | /** |
| 17 | * A list of the inputs that are never flashed for validation exceptions. |
| 18 | * |
| 19 | * @var array<int, string> |
| 20 | */ |
| 21 | protected $dontFlash = [ |
| 22 | 'current_password', |
| 23 | 'password', |
| 24 | 'password_confirmation', |
| 25 | ]; |
| 26 | |
| 27 | private static bool $alreadyRenderErrorPage = false; |
| 28 | |
| 29 | public function __construct( |
| 30 | Container $container, |
| 31 | private ExceptionHandler $internal |
| 32 | ) { |
| 33 | parent::__construct($container); |
| 34 | } |
| 35 | |
| 36 | public function report(Throwable $e): void |
| 37 | { |
| 38 | IntegrationTestLogger::logException($e); |
| 39 | $this->internal->report($e); |
| 40 | } |
| 41 | |
| 42 | public function shouldReport(Throwable $e): bool |
| 43 | { |
| 44 | return $this->internal->shouldReport($e); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * @param \Symfony\Component\Console\Output\OutputInterface $output |
| 49 | */ |
| 50 | public function renderForConsole($output, Throwable $e): void |
| 51 | { |
| 52 | $this->internal->renderForConsole($output, $e); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * @param \Illuminate\Http\Request $request |
| 57 | */ |
| 58 | public function render($request, Throwable $e): Response|HttpResponse |
| 59 | { |
| 60 | $response = null; |
| 61 | if (!self::$alreadyRenderErrorPage) { |
| 62 | self::$alreadyRenderErrorPage = true; |
| 63 | try { |
| 64 | /** @var ApieErrorRenderer $apieErrorHandler */ |
| 65 | $apieErrorHandler = resolve(ApieErrorRenderer::class); |
| 66 | if ($apieErrorHandler->isApieRequest($request) || $e instanceof ApieException) { |
| 67 | if ($apieErrorHandler->canCreateCmsResponse($request)) { |
| 68 | $response = $apieErrorHandler->createCmsResponse($request, $e); |
| 69 | } else { |
| 70 | $response = $apieErrorHandler->createApiResponse($e); |
| 71 | } |
| 72 | } |
| 73 | } finally { |
| 74 | self::$alreadyRenderErrorPage = false; |
| 75 | } |
| 76 | } |
| 77 | if ($response) { |
| 78 | return $response; |
| 79 | } |
| 80 | return $this->internal->render($request, $e); |
| 81 | } |
| 82 | } |