24 lines
524 B
PHP
24 lines
524 B
PHP
<?php
|
|
|
|
namespace App\Services\Graph;
|
|
|
|
use Throwable;
|
|
|
|
class GraphErrorMapper
|
|
{
|
|
public static function fromThrowable(Throwable $throwable, array $context = []): GraphException
|
|
{
|
|
if ($throwable instanceof GraphException) {
|
|
return $throwable;
|
|
}
|
|
|
|
$code = (int) ($throwable->getCode() ?: 0);
|
|
|
|
return new GraphException(
|
|
$throwable->getMessage(),
|
|
$code > 0 ? $code : null,
|
|
$context + ['exception' => get_class($throwable)]
|
|
);
|
|
}
|
|
}
|