1
1
<?php
2
+
2
3
/**
3
- * Copyright 2024 Adobe
4
- * All Rights Reserved .
4
+ * Copyright © Magento, Inc. All rights reserved.
5
+ * See COPYING.txt for license details .
5
6
*/
7
+
6
8
declare (strict_types=1 );
7
9
8
10
namespace Magento \GraphQl \Controller ;
9
11
10
- use Exception ;
11
12
use Magento \Framework \App \Area ;
12
13
use Magento \Framework \App \AreaList ;
13
14
use Magento \Framework \App \FrontControllerInterface ;
23
24
use Magento \Framework \GraphQl \Query \QueryProcessor ;
24
25
use Magento \Framework \GraphQl \Query \Resolver \ContextInterface ;
25
26
use Magento \Framework \GraphQl \Schema \SchemaGeneratorInterface ;
26
- use Magento \Framework \GraphQl \Exception \GraphQlAuthenticationException ;
27
- use Magento \Framework \GraphQl \Exception \GraphQlAuthorizationException ;
28
27
use Magento \Framework \Serialize \SerializerInterface ;
29
28
use Magento \Framework \Webapi \Response ;
30
29
use Magento \GraphQl \Helper \Query \Logger \LogData ;
@@ -185,7 +184,7 @@ public function dispatch(RequestInterface $request): ResponseInterface
185
184
$ statusCode = 200 ;
186
185
$ jsonResult = $ this ->jsonFactory ->create ();
187
186
$ data = $ this ->getDataFromRequest ($ request );
188
- $ result = [' errors ' => [] ];
187
+ $ result = [];
189
188
190
189
$ schema = null ;
191
190
$ query = $ data ['query ' ] ?? '' ;
@@ -206,14 +205,8 @@ public function dispatch(RequestInterface $request): ResponseInterface
206
205
$ this ->contextFactory ->create (),
207
206
$ data ['variables ' ] ?? []
208
207
);
209
- $ statusCode = $ this ->getHttpResponseCode ($ result );
210
- } catch (GraphQlAuthenticationException $ error ) {
211
- $ result ['errors ' ][] = $ this ->graphQlError ->create ($ error );
212
- $ statusCode = 401 ;
213
- } catch (GraphQlAuthorizationException $ error ) {
214
- $ result ['errors ' ][] = $ this ->graphQlError ->create ($ error );
215
- $ statusCode = 403 ;
216
- } catch (Exception $ error ) {
208
+ } catch (\Exception $ error ) {
209
+ $ result ['errors ' ] = isset ($ result ['errors ' ]) ? $ result ['errors ' ] : [];
217
210
$ result ['errors ' ][] = $ this ->graphQlError ->create ($ error );
218
211
$ statusCode = ExceptionFormatter::HTTP_GRAPH_QL_SCHEMA_ERROR_STATUS ;
219
212
}
@@ -223,7 +216,7 @@ public function dispatch(RequestInterface $request): ResponseInterface
223
216
$ jsonResult ->renderResult ($ this ->httpResponse );
224
217
225
218
// log information about the query, unless it is an introspection query
226
- if (! str_contains ($ query , 'IntrospectionQuery ' )) {
219
+ if (strpos ($ query , 'IntrospectionQuery ' ) === false ) {
227
220
$ queryInformation = $ this ->logDataHelper ->getLogData ($ request , $ data , $ schema , $ this ->httpResponse );
228
221
$ this ->loggerPool ->execute ($ queryInformation );
229
222
}
@@ -254,30 +247,4 @@ private function getDataFromRequest(RequestInterface $request): array
254
247
255
248
return $ data ;
256
249
}
257
-
258
- /**
259
- * Retrieve http response code based on the error categories
260
- *
261
- * @param array $result
262
- * @return int
263
- */
264
- private function getHttpResponseCode (array $ result ): int
265
- {
266
- if (empty ($ result ['errors ' ])) {
267
- return 200 ;
268
- }
269
- foreach ($ result ['errors ' ] as $ error ) {
270
- if (!isset ($ error ['extensions ' ]['category ' ])) {
271
- continue ;
272
- }
273
- switch ($ error ['extensions ' ]['category ' ]) {
274
- case GraphQlAuthenticationException::EXCEPTION_CATEGORY :
275
- return 401 ;
276
- case GraphQlAuthorizationException::EXCEPTION_CATEGORY :
277
- return 403 ;
278
- }
279
- }
280
-
281
- return 200 ;
282
- }
283
250
}
0 commit comments