Skip to content

Commit

Permalink
Add custom handlers for dependency exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
askvortsov1 committed Sep 6, 2020
1 parent 6147ee9 commit 7825b50
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/Extension/Exception/DependentExtensionsExceptionHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/

namespace Flarum\Extension\Exception;

use Flarum\Foundation\ErrorHandling\HandledError;

class DependentExtensionsExceptionHandler
{
public function handle(DependentExtensionsException $e): HandledError
{
return (new HandledError(
$e,
'dependent_extensions',
409
))->withDetails($this->errorDetails($e));
}

protected function errorDetails(DependentExtensionsException $e): array
{
return [
[
'extension' => $e->extension->getId(),
'dependent_dependencies' => $e->dependent_dependencies
]
];
}
}
34 changes: 34 additions & 0 deletions src/Extension/Exception/MissingDependenciesExceptionHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/

namespace Flarum\Extension\Exception;

use Flarum\Foundation\ErrorHandling\HandledError;

class MissingDependenciesExceptionHandler
{
public function handle(MissingDependenciesException $e): HandledError
{
return (new HandledError(
$e,
'missing_dependencies',
409
))->withDetails($this->errorDetails($e));
}

protected function errorDetails(MissingDependenciesException $e): array
{
return [
[
'extension' => $e->extension->getId(),
'missing_dependencies' => $e->missing_dependencies
]
];
}
}
6 changes: 6 additions & 0 deletions src/Foundation/ErrorServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

namespace Flarum\Foundation;

use Flarum\Extension\Exception\DependentExtensionsException;
use Flarum\Extension\Exception\DependentExtensionsExceptionHandler;
use Flarum\Extension\Exception\MissingDependenciesException;
use Flarum\Extension\Exception\MissingDependenciesExceptionHandler;
use Flarum\Foundation\ErrorHandling\ExceptionHandler;
use Flarum\Foundation\ErrorHandling\LogReporter;
use Flarum\Foundation\ErrorHandling\Registry;
Expand Down Expand Up @@ -57,6 +61,8 @@ public function register()
return [
IlluminateValidationException::class => ExceptionHandler\IlluminateValidationExceptionHandler::class,
ValidationException::class => ExceptionHandler\ValidationExceptionHandler::class,
DependentExtensionsException::class => DependentExtensionsExceptionHandler::class,
MissingDependenciesException::class => MissingDependenciesExceptionHandler::class,
];
});

Expand Down

0 comments on commit 7825b50

Please sign in to comment.