Chris@18
|
1 <?php
|
Chris@18
|
2
|
Chris@18
|
3 namespace Drupal\jsonapi\Exception;
|
Chris@18
|
4
|
Chris@18
|
5 use Drupal\Core\Entity\EntityConstraintViolationListInterface;
|
Chris@18
|
6 use Drupal\Core\DependencyInjection\DependencySerializationTrait;
|
Chris@18
|
7 use Symfony\Component\HttpKernel\Exception\HttpException;
|
Chris@18
|
8
|
Chris@18
|
9 /**
|
Chris@18
|
10 * A class to represent a 422 - Unprocessable Entity Exception.
|
Chris@18
|
11 *
|
Chris@18
|
12 * The HTTP 422 status code is used when the server sees:-
|
Chris@18
|
13 *
|
Chris@18
|
14 * The content type of the request is correct.
|
Chris@18
|
15 * The syntax of the request is correct.
|
Chris@18
|
16 * BUT was unable to process the contained instruction.
|
Chris@18
|
17 *
|
Chris@18
|
18 * @internal JSON:API maintains no PHP API. The API is the HTTP API. This class
|
Chris@18
|
19 * may change at any time and could break any dependencies on it.
|
Chris@18
|
20 *
|
Chris@18
|
21 * @see https://www.drupal.org/project/jsonapi/issues/3032787
|
Chris@18
|
22 * @see jsonapi.api.php
|
Chris@18
|
23 */
|
Chris@18
|
24 class UnprocessableHttpEntityException extends HttpException {
|
Chris@18
|
25
|
Chris@18
|
26 use DependencySerializationTrait;
|
Chris@18
|
27
|
Chris@18
|
28 /**
|
Chris@18
|
29 * The constraint violations associated with this exception.
|
Chris@18
|
30 *
|
Chris@18
|
31 * @var \Drupal\Core\Entity\EntityConstraintViolationListInterface
|
Chris@18
|
32 */
|
Chris@18
|
33 protected $violations;
|
Chris@18
|
34
|
Chris@18
|
35 /**
|
Chris@18
|
36 * UnprocessableHttpEntityException constructor.
|
Chris@18
|
37 *
|
Chris@18
|
38 * @param \Exception|null $previous
|
Chris@18
|
39 * The pervious error, if any, associated with the request.
|
Chris@18
|
40 * @param array $headers
|
Chris@18
|
41 * The headers associated with the request.
|
Chris@18
|
42 * @param int $code
|
Chris@18
|
43 * The HTTP status code associated with the request. Defaults to zero.
|
Chris@18
|
44 */
|
Chris@18
|
45 public function __construct(\Exception $previous = NULL, array $headers = [], $code = 0) {
|
Chris@18
|
46 parent::__construct(422, "Unprocessable Entity: validation failed.", $previous, $headers, $code);
|
Chris@18
|
47 }
|
Chris@18
|
48
|
Chris@18
|
49 /**
|
Chris@18
|
50 * Gets the constraint violations associated with this exception.
|
Chris@18
|
51 *
|
Chris@18
|
52 * @return \Drupal\Core\Entity\EntityConstraintViolationListInterface
|
Chris@18
|
53 * The constraint violations.
|
Chris@18
|
54 */
|
Chris@18
|
55 public function getViolations() {
|
Chris@18
|
56 return $this->violations;
|
Chris@18
|
57 }
|
Chris@18
|
58
|
Chris@18
|
59 /**
|
Chris@18
|
60 * Sets the constraint violations associated with this exception.
|
Chris@18
|
61 *
|
Chris@18
|
62 * @param \Drupal\Core\Entity\EntityConstraintViolationListInterface $violations
|
Chris@18
|
63 * The constraint violations.
|
Chris@18
|
64 */
|
Chris@18
|
65 public function setViolations(EntityConstraintViolationListInterface $violations) {
|
Chris@18
|
66 $this->violations = $violations;
|
Chris@18
|
67 }
|
Chris@18
|
68
|
Chris@18
|
69 }
|