Skip to content

Commit 770956e

Browse files
committed
Set 422 as default error code
1 parent f07d52a commit 770956e

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/Exception/ValidationException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class ValidationException extends DomainException
2727
public function __construct(
2828
string $message,
2929
ValidationResult $validationResult,
30-
int $code = 0,
30+
int $code = 422,
3131
Throwable $previous = null
3232
) {
3333
parent::__construct($message, $code, $previous);

tests/Middleware/ErrorMiddleware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
3030

3131
$validation->addError('username', 'Input required');
3232

33-
throw new ValidationException('Please check your input', $validation);
33+
throw new ValidationException('Please check your input', $validation, 422);
3434
}
3535
}

tests/Middleware/ValidationExceptionMiddlewareTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ValidationExceptionMiddlewareTest extends TestCase
2323
*
2424
* @return void
2525
*/
26-
public function testNoError()
26+
public function testNoError(): void
2727
{
2828
$middleware = new ValidationExceptionMiddleware(
2929
new ResponseFactory(),
@@ -44,7 +44,7 @@ public function testNoError()
4444
*
4545
* @return void
4646
*/
47-
public function testWithError()
47+
public function testWithError(): void
4848
{
4949
$middleware = new ValidationExceptionMiddleware(
5050
new ResponseFactory(),
@@ -58,7 +58,7 @@ public function testWithError()
5858
]);
5959

6060
static::assertSame(
61-
'{"error":{"message":"Please check your input","details":' .
61+
'{"error":{"message":"Please check your input","code":422,"details":' .
6262
'[{"message":"Input required","field":"username"}]}}',
6363
(string)$response->getBody()
6464
);

0 commit comments

Comments
 (0)