Skip to content

Commit

Permalink
Add getVerboseMessage to AddressValidationFailed exception
Browse files Browse the repository at this point in the history
  • Loading branch information
DEVizzent committed Feb 19, 2023
1 parent f6af720 commit 464eb0a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/PSR7/Exception/Validation/AddressValidationFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@

use League\OpenAPIValidation\PSR7\Exception\ValidationFailed;
use League\OpenAPIValidation\PSR7\OperationAddress;
use League\OpenAPIValidation\Schema\Exception\SchemaMismatch;
use Throwable;

use function implode;
use function rtrim;
use function sprintf;

abstract class AddressValidationFailed extends ValidationFailed
Expand Down Expand Up @@ -42,6 +45,21 @@ public static function fromAddr(OperationAddress $address): self
return $ex;
}

public function getVerboseMessage(): string
{
$previous = $this->getPrevious();
if (! $previous instanceof SchemaMismatch) {
return $this->getMessage();
}

return sprintf(
'%s. [%s in %s]',
$this->getMessage(),
rtrim($previous->getMessage(), '.'),
implode('->', $previous->dataBreadCrumb()->buildChain())
);
}

public function getAddress(): OperationAddress
{
return $this->address;
Expand Down

0 comments on commit 464eb0a

Please sign in to comment.