-
Notifications
You must be signed in to change notification settings - Fork 5
/
JsonValidationException.php
50 lines (43 loc) · 1.19 KB
/
JsonValidationException.php
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/*
* This file is part of the JsonValidationBundle package.
*
* (c) John Noel <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace JoiPolloi\Bundle\JsonValidationBundle\Exception;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
/**
* JSON validation exception
*
* Triggered when JSON validation fails and can be caught separately in order
* to throw, for instance, application/problem+json response
*
* @author John Noel <[email protected]>
* @package JsonValidationBundle
*/
class JsonValidationException extends BadRequestHttpException
{
/** @var array */
protected $errors;
/**
* @param string $message The exception message
* @param array $errors Any validation errors
*/
public function __construct(string $message, array $errors = [])
{
$this->errors = $errors;
parent::__construct($message);
}
/**
* Get the validation errors (if any) that triggered this exception
*
* @return array
*/
public function getErrors() : array
{
return $this->errors;
}
}