File tree Expand file tree Collapse file tree 2 files changed +49
-11
lines changed
lib/internal/Magento/Framework/GraphQl Expand file tree Collapse file tree 2 files changed +49
-11
lines changed Original file line number Diff line number Diff line change 7
7
8
8
namespace Magento \Framework \GraphQl \Exception ;
9
9
10
- use Magento \Framework \Exception \InputException ;
10
+ use Magento \Framework \Exception \AggregateExceptionInterface ;
11
+ use Magento \Framework \Exception \LocalizedException ;
11
12
use Magento \Framework \Phrase ;
13
+ use GraphQL \Error \ClientAware ;
12
14
13
15
/**
14
16
* Exception for GraphQL to be thrown when user supplies invalid input
15
17
*/
16
- class GraphQlInputException extends InputException implements \ GraphQL \ Error \ ClientAware
18
+ class GraphQlInputException extends LocalizedException implements AggregateExceptionInterface, ClientAware
17
19
{
18
20
const EXCEPTION_CATEGORY = 'graphql-input ' ;
19
21
@@ -22,6 +24,13 @@ class GraphQlInputException extends InputException implements \GraphQL\Error\Cli
22
24
*/
23
25
private $ isSafe ;
24
26
27
+ /**
28
+ * The array of errors that have been added via the addError() method
29
+ *
30
+ * @var \Magento\Framework\Exception\LocalizedException[]
31
+ */
32
+ private $ errors = [];
33
+
25
34
/**
26
35
* Initialize object
27
36
*
@@ -51,4 +60,26 @@ public function getCategory() : string
51
60
{
52
61
return self ::EXCEPTION_CATEGORY ;
53
62
}
63
+
64
+ /**
65
+ * Add child error if used as aggregate exception
66
+ *
67
+ * @param LocalizedException $exception
68
+ * @return $this
69
+ */
70
+ public function addError (LocalizedException $ exception ): self
71
+ {
72
+ $ this ->errors [] = $ exception ;
73
+ return $ this ;
74
+ }
75
+
76
+ /**
77
+ * Get child errors if used as aggregate exception
78
+ *
79
+ * @return LocalizedException[]
80
+ */
81
+ public function getErrors (): array
82
+ {
83
+ return $ this ->errors ;
84
+ }
54
85
}
Original file line number Diff line number Diff line change 7
7
8
8
namespace Magento \Framework \GraphQl \Query ;
9
9
10
- use GraphQL \ Error \ ClientAware ;
10
+ use Magento \ Framework \ Exception \ AggregateExceptionInterface ;
11
11
use Psr \Log \LoggerInterface ;
12
12
13
13
/**
@@ -36,13 +36,20 @@ public function __construct(
36
36
*/
37
37
public function handle (array $ errors , callable $ formatter ): array
38
38
{
39
- return array_map (
40
- function (ClientAware $ error ) use ($ formatter ) {
41
- $ this ->logger ->error ($ error );
42
-
43
- return $ formatter ($ error );
44
- },
45
- $ errors
46
- );
39
+ $ formattedErrors = [];
40
+ foreach ($ errors as $ error ) {
41
+ $ this ->logger ->error ($ error );
42
+ $ previousError = $ error ->getPrevious ();
43
+ if ($ previousError instanceof AggregateExceptionInterface && !empty ($ previousError ->getErrors ())) {
44
+ $ aggregatedErrors = $ previousError ->getErrors ();
45
+ foreach ($ aggregatedErrors as $ aggregatedError ) {
46
+ $ this ->logger ->error ($ aggregatedError );
47
+ $ formattedErrors [] = $ formatter ($ aggregatedError );
48
+ }
49
+ } else {
50
+ $ formattedErrors [] = $ formatter ($ error );
51
+ }
52
+ }
53
+ return $ formattedErrors ;
47
54
}
48
55
}
You can’t perform that action at this time.
0 commit comments