1 | <?php namespace Neomerx\JsonApi\Exceptions; |
||
27 | class JsonApiException extends RuntimeException |
||
28 | { |
||
29 | /** Default HTTP code */ |
||
30 | const HTTP_CODE_BAD_REQUEST = 400; |
||
31 | |||
32 | /** Default HTTP code */ |
||
33 | const HTTP_CODE_FORBIDDEN = 403; |
||
34 | |||
35 | /** Default HTTP code */ |
||
36 | const HTTP_CODE_NOT_ACCEPTABLE = 406; |
||
37 | |||
38 | /** Default HTTP code */ |
||
39 | const HTTP_CODE_CONFLICT = 409; |
||
40 | |||
41 | /** Default HTTP code */ |
||
42 | const HTTP_CODE_UNSUPPORTED_MEDIA_TYPE = 415; |
||
43 | |||
44 | /** Default HTTP code */ |
||
45 | const DEFAULT_HTTP_CODE = self::HTTP_CODE_BAD_REQUEST; |
||
46 | |||
47 | /** |
||
48 | * @var ErrorCollection |
||
49 | */ |
||
50 | private $errors; |
||
51 | |||
52 | /** |
||
53 | * @var int |
||
54 | */ |
||
55 | private $httpCode; |
||
56 | |||
57 | /** |
||
58 | * Constructor. |
||
59 | * |
||
60 | * @param Error|Error[]|ErrorCollection $errors |
||
61 | * @param int $httpCode |
||
62 | * @param Exception|null $previous |
||
63 | */ |
||
64 | 19 | public function __construct($errors, $httpCode = self::DEFAULT_HTTP_CODE, Exception $previous = null) |
|
81 | |||
82 | /** |
||
83 | * @param Error $error |
||
84 | */ |
||
85 | 3 | public function addError(Error $error) |
|
89 | |||
90 | /** |
||
91 | * @param ErrorCollection $errors |
||
92 | * |
||
93 | * @return void |
||
94 | */ |
||
95 | 1 | public function addErrors(ErrorCollection $errors) |
|
101 | |||
102 | /** |
||
103 | * @param Error[] $errors |
||
104 | * |
||
105 | * @return void |
||
106 | */ |
||
107 | 17 | public function addErrorsFromArray(array $errors) |
|
113 | |||
114 | /** |
||
115 | * @return ErrorCollection |
||
116 | */ |
||
117 | 3 | public function getErrors() |
|
121 | |||
122 | /** |
||
123 | * @return int |
||
124 | */ |
||
125 | 11 | public function getHttpCode() |
|
129 | |||
130 | /** |
||
131 | * @param JsonApiException $exception |
||
132 | */ |
||
133 | 12 | public static function throwException(JsonApiException $exception) |
|
137 | } |
||
138 |