-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbstractException.php
55 lines (44 loc) · 1.32 KB
/
AbstractException.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
declare(strict_types=1);
namespace Ankurk91\StripeExceptions;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Config;
use Throwable;
abstract class AbstractException extends Exception
{
protected array $dontReport = [
//
];
public function __construct(Throwable $exception)
{
parent::__construct($exception->getMessage(), (int)$exception->getCode(), $exception);
}
public function report(): ?bool
{
$original = $this->getPrevious();
if (!$this->shouldReport($original)) {
return null; // must return null value to skip
}
return false; // let Laravel exception handler do the rest
}
public function shouldReport(Throwable $exception): bool
{
if (Config::get('app.debug')) {
return true;
}
$foundInReportList = Arr::first($this->dontReport, function ($class) use ($exception) {
return $exception instanceof $class;
});
return is_null($foundInReportList);
}
/**
* Render the exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
*/
abstract function render(Request $request);
}