If you want to add solutions to exceptions that you can't modify, you can use a solution provider. A solution provider is a class that implements the ProvidesSolution
interface. It will determine if it can provide a solution for a given exception.
Here's an example:
use Spatie\ErrorSolutions\Contracts\HasSolutionsForThrowable;
use Spatie\ErrorSolutions\Contracts\Solution;
use Throwable;
class YourSolutionProvider implements HasSolutionsForThrowable
{
public function canSolve(Throwable $throwable): bool
{
}
public function getSolutions(Throwable $throwable): array
{
}
}
##Registering your solution provider
After you've created your solution provider, you can register it in the solution_providers
key of the error-solutions.php
config file:
return [
'solution_providers' => [
YourSolutionProvider::class,
],
];
Alternatively, you can register your solution provider at runtime. Typically, this would be done in a service provider:
use Spatie\ErrorSolutions\ErrorSolutionsServiceProvider;
use Spatie\ErrorSolutions\Contracts\SolutionProviderRepository;
public function register()
{
$repository = app(SolutionProviderRepository::class);
$repository->registerSolutionProviders([
YourSolutionProvider::class,
]);
}