19
19
use Magento \Framework \App \ResponseInterface ;
20
20
use Magento \Framework \Controller \Result \JsonFactory ;
21
21
use Magento \Framework \GraphQl \Exception \ExceptionFormatter ;
22
- use Magento \Framework \GraphQl \Exception \GraphQlAuthenticationException ;
23
- use Magento \Framework \GraphQl \Exception \GraphQlAuthorizationException ;
24
22
use Magento \Framework \GraphQl \Exception \GraphQlInputException ;
25
23
use Magento \Framework \GraphQl \Query \Fields as QueryFields ;
26
24
use Magento \Framework \GraphQl \Query \QueryParser ;
@@ -187,7 +185,7 @@ public function dispatch(RequestInterface $request): ResponseInterface
187
185
$ statusCode = 200 ;
188
186
$ jsonResult = $ this ->jsonFactory ->create ();
189
187
$ data = [];
190
- $ result = [ ' errors ' => []] ;
188
+ $ result = null ;
191
189
$ schema = null ;
192
190
$ query = '' ;
193
191
@@ -213,13 +211,6 @@ public function dispatch(RequestInterface $request): ResponseInterface
213
211
$ data ['variables ' ] ?? []
214
212
);
215
213
}
216
- $ statusCode = $ this ->getHttpResponseCode ($ result );
217
- } catch (GraphQlAuthenticationException $ error ) {
218
- $ result ['errors ' ][] = $ this ->graphQlError ->create ($ error );
219
- $ statusCode = 401 ;
220
- } catch (GraphQlAuthorizationException $ error ) {
221
- $ result ['errors ' ][] = $ this ->graphQlError ->create ($ error );
222
- $ statusCode = 403 ;
223
214
} catch (SyntaxError |GraphQlInputException $ error ) {
224
215
$ result = [
225
216
'errors ' => [FormattedError::createFromException ($ error )],
@@ -239,35 +230,14 @@ public function dispatch(RequestInterface $request): ResponseInterface
239
230
$ jsonResult ->renderResult ($ this ->httpResponse );
240
231
241
232
// log information about the query, unless it is an introspection query
242
- if (! str_contains ($ query , 'IntrospectionQuery ' )) {
233
+ if (strpos ($ query , 'IntrospectionQuery ' ) === false ) {
243
234
$ queryInformation = $ this ->logDataHelper ->getLogData ($ request , $ data , $ schema , $ this ->httpResponse );
244
235
$ this ->loggerPool ->execute ($ queryInformation );
245
236
}
246
237
247
238
return $ this ->httpResponse ;
248
239
}
249
240
250
- /**
251
- * Retrieve http response code based on the error categories
252
- *
253
- * @param array $result
254
- * @return int
255
- */
256
- private function getHttpResponseCode (array $ result ): int
257
- {
258
- foreach ($ result ['errors ' ] ?? [] as $ error ) {
259
- if (isset ($ error ['extensions ' ]['category ' ])) {
260
- return match ($ error ['extensions ' ]['category ' ]) {
261
- GraphQlAuthenticationException::EXCEPTION_CATEGORY => 401 ,
262
- GraphQlAuthorizationException::EXCEPTION_CATEGORY => 403 ,
263
- default => 200 ,
264
- };
265
- }
266
- }
267
-
268
- return 200 ;
269
- }
270
-
271
241
/**
272
242
* Get data from request body or query string
273
243
*
0 commit comments