Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ new ValidationApiProblem(new ConstraintViolationList([
}
````

The status code defaults to 400 and can be overridden:

```php
new ValidationApiProblem($violationList, 422);
```

#### BadRequestProblem

```php
Expand Down
6 changes: 6 additions & 0 deletions spec/Http/ValidationApiProblemSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public function it_is_an_http_api_problem(): void
$this->shouldHaveType(HttpApiProblem::class);
}

public function it_can_be_constructed_with_a_custom_status_code(): void
{
$this->beConstructedWith(new ConstraintViolationList([]), 422);
$this->toArray()->shouldHaveKeyWithValue('status', 422);
}

public function it_can_parse_to_array(): void
{
$this->toArray()->shouldBe([
Expand Down
4 changes: 2 additions & 2 deletions src/Http/ValidationApiProblem.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ class ValidationApiProblem extends HttpApiProblem
{
public const TYPE_SYMFONY_VIOLATIONS = 'https://symfony.com/errors/validation';

public function __construct(ConstraintViolationListInterface $violationList)
public function __construct(ConstraintViolationListInterface $violationList, int $statusCode = 400)
{
parent::__construct(
400,
$statusCode,
[
'type' => self::TYPE_SYMFONY_VIOLATIONS,
'title' => 'Validation Failed',
Expand Down
Loading