4
4
5
5
namespace WebServCo \JSONAPI \Service \Handler ;
6
6
7
+ use Error ;
7
8
use Fig \Http \Message \RequestMethodInterface ;
9
+ use Fig \Http \Message \StatusCodeInterface ;
8
10
use OutOfBoundsException ;
9
11
use Psr \Http \Message \ServerRequestInterface ;
10
12
use UnexpectedValueException ;
@@ -57,7 +59,7 @@ public function handleRequest(ServerRequestInterface $request): bool
57
59
{
58
60
// Check request method.
59
61
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 ) );
61
63
62
64
return false ;
63
65
}
@@ -67,7 +69,7 @@ public function handleRequest(ServerRequestInterface $request): bool
67
69
68
70
// Check content type.
69
71
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 ) );
71
73
72
74
return false ;
73
75
}
@@ -115,7 +117,10 @@ private function handleFormProcessing(array $requestBodyAsArray): bool
115
117
),
116
118
);
117
119
} catch (OutOfBoundsException $ e ) {
118
- $ this ->addFormFieldErrorMessage ($ e ->getMessage (), $ formField );
120
+ $ this ->addFormFieldErrorMessage (
121
+ new Error ($ e ->getMessage (), StatusCodeInterface::STATUS_BAD_REQUEST ),
122
+ $ formField ,
123
+ );
119
124
}
120
125
}
121
126
@@ -140,12 +145,12 @@ private function handleVersionMatchCheck(array $requestBodyAsArray): bool
140
145
141
146
try {
142
147
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 ) );
144
149
145
150
return false ;
146
151
}
147
152
} catch (OutOfBoundsException $ exception ) {
148
- $ this ->addErrorMessage ( $ exception ->getMessage ());
153
+ $ this ->addError ( new Error ( $ exception ->getMessage (), StatusCodeInterface:: STATUS_BAD_REQUEST ));
149
154
150
155
return false ;
151
156
}
0 commit comments