Skip to content

Commit

Permalink
Add method to include exception
Browse files Browse the repository at this point in the history
  • Loading branch information
juniwalk authored Feb 13, 2024
1 parent 38e4298 commit 86d525f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Entity/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Doctrine\ORM\Proxy\Proxy;
use JuniWalk\ORM\Traits as Tools;
use JuniWalk\Nestor\Enums\Type;
use JuniWalk\Nestor\Interfaces\ParamsProvider;
use JuniWalk\Utils\Arrays;
use JuniWalk\Utils\Enums\Color;
use JuniWalk\Utils\Format;
Expand Down Expand Up @@ -139,6 +140,11 @@ public function setTarget(object $target, ?int $targetId = null): void
$this->target = $target::class;
$this->targetId = $targetId;

// ? Could colide agains withParams method
// if ($target instanceof ParamsProvider) {
// $this->params = $target->getRecordParams();
// }

if ($target instanceof Proxy) {
$this->target = get_parent_class($target);
}
Expand Down
13 changes: 13 additions & 0 deletions src/RecordBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
use JuniWalk\Nestor\Entity\Record;
use JuniWalk\Nestor\Enums\Type;
use JuniWalk\Nestor\Exceptions\RecordNotValidException;
use JuniWalk\Utils\Format;
use JuniWalk\Utils\Enums\Color;
use JuniWalk\Utils\Strings;
use Nette\Security\IIdentity as Identity;
use Throwable;

final class RecordBuilder
{
Expand Down Expand Up @@ -81,6 +83,17 @@ public function withNote(?string $note): static
}


public function withError(?Throwable $e): static
{
if (!$e instanceof Throwable) {
return $this;
}

$this->record['note'] = Format::className($e).': '.$e->getMessage();
return $this;
}


public function withEvent(?string $event): static
{
$this->record['event'] = $event;
Expand Down

0 comments on commit 86d525f

Please sign in to comment.