Skip to content

Commit cea3472

Browse files
committed
Use StatusCodeInterface
1 parent 4bfe1db commit cea3472

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/WebServCo/JSONAPI/Service/Handler/JSONAPIItemHandler.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
namespace WebServCo\JSONAPI\Service\Handler;
66

7+
use Error;
78
use Fig\Http\Message\RequestMethodInterface;
9+
use Fig\Http\Message\StatusCodeInterface;
810
use OutOfBoundsException;
911
use Psr\Http\Message\ServerRequestInterface;
1012
use UnexpectedValueException;
@@ -57,7 +59,7 @@ public function handleRequest(ServerRequestInterface $request): bool
5759
{
5860
// Check request method.
5961
if (!in_array($request->getMethod(), $this->acceptableRequestMethods, true)) {
60-
$this->addErrorMessage('Request method does not match');
62+
$this->addError(new Error('Request method does not match', StatusCodeInterface::STATUS_BAD_REQUEST));
6163

6264
return false;
6365
}
@@ -67,7 +69,7 @@ public function handleRequest(ServerRequestInterface $request): bool
6769

6870
// Check content type.
6971
if (!$this->requestService->validateContentType($request)) {
70-
$this->addErrorMessage('Content type does not match.');
72+
$this->addError(new Error('Content type does not match.', StatusCodeInterface::STATUS_BAD_REQUEST));
7173

7274
return false;
7375
}
@@ -115,7 +117,10 @@ private function handleFormProcessing(array $requestBodyAsArray): bool
115117
),
116118
);
117119
} catch (OutOfBoundsException $e) {
118-
$this->addFormFieldErrorMessage($e->getMessage(), $formField);
120+
$this->addFormFieldErrorMessage(
121+
new Error($e->getMessage(), StatusCodeInterface::STATUS_BAD_REQUEST),
122+
$formField,
123+
);
119124
}
120125
}
121126

@@ -140,12 +145,12 @@ private function handleVersionMatchCheck(array $requestBodyAsArray): bool
140145

141146
try {
142147
if (!$this->requestService->versionMatches($requestBodyAsArray, 1.1)) {
143-
$this->addErrorMessage('JSONAPI version does not match.');
148+
$this->addError(new Error('JSONAPI version does not match.', StatusCodeInterface::STATUS_BAD_REQUEST));
144149

145150
return false;
146151
}
147152
} catch (OutOfBoundsException $exception) {
148-
$this->addErrorMessage($exception->getMessage());
153+
$this->addError(new Error($exception->getMessage(), StatusCodeInterface::STATUS_BAD_REQUEST));
149154

150155
return false;
151156
}

0 commit comments

Comments
 (0)