added nice "error 500" pages, fixed core system migration
This commit is contained in:
@@ -3,8 +3,15 @@
|
||||
namespace App\Exceptions;
|
||||
|
||||
use App\Support\ApiError;
|
||||
use Illuminate\Database\Connectors\ConnectionException as DatabaseConnectionException;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Illuminate\Http\Client\ConnectionException as HttpClientConnectionException;
|
||||
use Illuminate\Queue\InvalidQueueException;
|
||||
use Illuminate\Queue\MaxAttemptsExceededException;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use League\Flysystem\FilesystemException;
|
||||
use PDOException;
|
||||
use Throwable;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
@@ -63,6 +70,12 @@ class Handler extends ExceptionHandler
|
||||
}
|
||||
}
|
||||
|
||||
if (! $request->expectsJson() && ! $request->inertia()) {
|
||||
if ($hintKey = $this->resolveServerErrorHint($e)) {
|
||||
$request->attributes->set('serverErrorHint', __($hintKey, [], app()->getLocale()));
|
||||
}
|
||||
}
|
||||
|
||||
return parent::render($request, $e);
|
||||
}
|
||||
|
||||
@@ -74,4 +87,81 @@ class Handler extends ExceptionHandler
|
||||
|
||||
return 'Your request could not be processed. Please verify the details and try again.';
|
||||
}
|
||||
|
||||
private function resolveServerErrorHint(Throwable $throwable): ?string
|
||||
{
|
||||
$status = $this->isHttpException($throwable)
|
||||
? $this->toHttpException($throwable)->getStatusCode()
|
||||
: 500;
|
||||
|
||||
if ($status < 500) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($this->exceptionChainContains($throwable, [
|
||||
QueryException::class,
|
||||
DatabaseConnectionException::class,
|
||||
PDOException::class,
|
||||
'Doctrine\\DBAL\\Exception',
|
||||
])) {
|
||||
return 'marketing.server_error.hints.database';
|
||||
}
|
||||
|
||||
if ($this->exceptionChainContains($throwable, [
|
||||
FilesystemException::class,
|
||||
'League\\Flysystem\\UnableToWriteFile',
|
||||
'League\\Flysystem\\UnableToCreateDirectory',
|
||||
'League\\Flysystem\\UnableToCheckExistence',
|
||||
])) {
|
||||
return 'marketing.server_error.hints.storage';
|
||||
}
|
||||
|
||||
if ($this->exceptionChainContains($throwable, [
|
||||
InvalidQueueException::class,
|
||||
MaxAttemptsExceededException::class,
|
||||
'RedisException',
|
||||
'Predis\\Connection\\ConnectionException',
|
||||
])) {
|
||||
return 'marketing.server_error.hints.queue';
|
||||
}
|
||||
|
||||
if ($this->exceptionChainContains($throwable, [
|
||||
HttpClientConnectionException::class,
|
||||
'GuzzleHttp\\Exception\\ConnectException',
|
||||
'Psr\\Http\\Client\\NetworkExceptionInterface',
|
||||
'Symfony\\Component\\HttpClient\\Exception\\TransportExceptionInterface',
|
||||
])) {
|
||||
return 'marketing.server_error.hints.network';
|
||||
}
|
||||
|
||||
return 'marketing.server_error.hints.generic';
|
||||
}
|
||||
|
||||
private function exceptionChainContains(Throwable $throwable, array $classNames): bool
|
||||
{
|
||||
do {
|
||||
foreach ($classNames as $className) {
|
||||
if ($this->throwableIsInstanceOf($throwable, $className)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$throwable = $throwable->getPrevious();
|
||||
} while ($throwable);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function throwableIsInstanceOf(Throwable $throwable, string $className): bool
|
||||
{
|
||||
if ($className === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! class_exists($className) && ! interface_exists($className)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $throwable instanceof $className;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user