-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathValidationException.php
More file actions
29 lines (22 loc) · 940 Bytes
/
ValidationException.php
File metadata and controls
29 lines (22 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
declare(strict_types=1);
namespace Osteel\OpenApi\Testing\Exceptions;
use Exception;
use League\OpenAPIValidation\PSR7\Exception\ValidationFailed;
use League\OpenAPIValidation\Schema\Exception\SchemaMismatch;
class ValidationException extends Exception
{
/** Build a new exception from a ValidationFailed exception. */
public static function fromValidationFailed(ValidationFailed $exception): ValidationException
{
$previous = $exception;
$message = $exception->getMessage();
while ($exception = $exception->getPrevious()) {
$message .= sprintf(': %s', $exception->getMessage());
if ($exception instanceof SchemaMismatch && ! empty($breadCrumb = $exception->dataBreadCrumb())) {
$message .= sprintf(' Field: %s', implode('.', $breadCrumb->buildChain()));
}
}
return new ValidationException($message, 0, $previous);
}
}