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 authored and scaytrase committed Mar 23, 2023
1 parent 77a01ac commit 0e25f98
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 0e25f98

Please sign in to comment.