1111
1212namespace Overblog \GraphQLBundle \Error ;
1313
14- use GraphQL \Error ;
14+ use GraphQL \Error \ Error as GraphQLError ;
1515use GraphQL \Executor \ExecutionResult ;
1616use Psr \Log \LoggerInterface ;
1717use Psr \Log \LogLevel ;
@@ -63,8 +63,8 @@ public function setUserErrorClass($userErrorClass)
6363 }
6464
6565 /**
66- * @param Error [] $errors
67- * @param bool $throwRawException
66+ * @param GraphQLError [] $errors
67+ * @param bool $throwRawException
6868 *
6969 * @return array
7070 *
@@ -79,7 +79,7 @@ protected function treatExceptions(array $errors, $throwRawException)
7979 ],
8080 ];
8181
82- /** @var Error $error */
82+ /** @var GraphQLError $error */
8383 foreach ($ errors as $ error ) {
8484 $ rawException = $ this ->convertException ($ error ->getPrevious ());
8585
@@ -111,7 +111,7 @@ protected function treatExceptions(array $errors, $throwRawException)
111111 if ($ rawException instanceof UserErrors) {
112112 $ rawExceptions = $ rawException ;
113113 foreach ($ rawExceptions ->getErrors () as $ rawException ) {
114- $ treatedExceptions ['errors ' ][] = Error ::createLocatedError ($ rawException , $ error ->nodes );
114+ $ treatedExceptions ['errors ' ][] = GraphQLError ::createLocatedError ($ rawException , $ error ->nodes );
115115 }
116116 continue ;
117117 }
@@ -123,19 +123,24 @@ protected function treatExceptions(array $errors, $throwRawException)
123123
124124 $ this ->logException ($ rawException , LogLevel::CRITICAL );
125125
126- $ treatedExceptions ['errors ' ][] = new Error (
126+ $ treatedExceptions ['errors ' ][] = new GraphQLError (
127127 $ this ->internalErrorMessage ,
128128 $ error ->nodes ,
129- $ rawException ,
130129 $ error ->getSource (),
131- $ error ->getPositions ()
130+ $ error ->getPositions (),
131+ $ error ->path ,
132+ $ rawException
132133 );
133134 }
134135
135136 return $ treatedExceptions ;
136137 }
137138
138- public function logException (\Exception $ exception , $ errorLevel = LogLevel::ERROR )
139+ /**
140+ * @param \Exception|\Error $exception
141+ * @param string $errorLevel
142+ */
143+ public function logException ($ exception , $ errorLevel = LogLevel::ERROR )
139144 {
140145 $ message = sprintf (
141146 '%s: %s[%d] (caught exception) at %s line %s. ' ,
@@ -154,15 +159,15 @@ public function handleErrors(ExecutionResult $executionResult, $throwRawExceptio
154159 $ exceptions = $ this ->treatExceptions ($ executionResult ->errors , $ throwRawException );
155160 $ executionResult ->errors = $ exceptions ['errors ' ];
156161 if (!empty ($ exceptions ['extensions ' ]['warnings ' ])) {
157- $ executionResult ->extensions ['warnings ' ] = array_map (['GraphQL\Error ' , 'formatError ' ], $ exceptions ['extensions ' ]['warnings ' ]);
162+ $ executionResult ->extensions ['warnings ' ] = array_map (['GraphQL\Error\Error ' , 'formatError ' ], $ exceptions ['extensions ' ]['warnings ' ]);
158163 }
159164 }
160165
161166 /**
162167 * Tries to convert a raw exception into a user warning or error
163168 * that is displayed to the user.
164169 *
165- * @param \Exception $rawException
170+ * @param \Exception|\Error $rawException
166171 *
167172 * @return \Exception|\Error
168173 */
@@ -172,8 +177,9 @@ protected function convertException($rawException = null)
172177 return ;
173178 }
174179
175- if (!empty ($ this ->exceptionMap [get_class ($ rawException )])) {
176- $ errorClass = $ this ->exceptionMap [get_class ($ rawException )];
180+ $ rawExceptionClass = get_class ($ rawException );
181+ if (isset ($ this ->exceptionMap [$ rawExceptionClass ])) {
182+ $ errorClass = $ this ->exceptionMap [$ rawExceptionClass ];
177183
178184 return new $ errorClass ($ rawException ->getMessage (), $ rawException ->getCode (), $ rawException );
179185 }
0 commit comments