mirror of
https://github.com/retailcrm/graphql-php.git
synced 2025-02-06 07:49:24 +03:00
Ability to re-throw resolver exceptions
This commit is contained in:
parent
a2be92937e
commit
1d38643538
@ -109,6 +109,15 @@ This will make each error entry to look like this:
|
|||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If you prefer first resolver exception to be re-thrown, use following flags:
|
||||||
|
```php
|
||||||
|
use GraphQL\Error\FormattedError;
|
||||||
|
$debug = FormattedError::INCLUDE_DEBUG_MESSAGE | FormattedError::RETHROW_RESOLVER_EXCEPTIONS;
|
||||||
|
|
||||||
|
// Following will throw if there was an exception in resolver during execution:
|
||||||
|
$result = GraphQL::executeQuery(/*args*/)->toArray($debug);
|
||||||
|
```
|
||||||
|
|
||||||
# Custom Error Handling and Formatting
|
# Custom Error Handling and Formatting
|
||||||
It is possible to define custom **formatter** and **handler** for result errors.
|
It is possible to define custom **formatter** and **handler** for result errors.
|
||||||
|
|
||||||
|
@ -871,6 +871,7 @@ class FormattedError
|
|||||||
{
|
{
|
||||||
const INCLUDE_DEBUG_MESSAGE = 1;
|
const INCLUDE_DEBUG_MESSAGE = 1;
|
||||||
const INCLUDE_TRACE = 2;
|
const INCLUDE_TRACE = 2;
|
||||||
|
const RETHROW_RESOLVER_EXCEPTIONS = 4;
|
||||||
|
|
||||||
public static function setInternalErrorMessage($msg);
|
public static function setInternalErrorMessage($msg);
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ class FormattedError
|
|||||||
{
|
{
|
||||||
const INCLUDE_DEBUG_MESSAGE = 1;
|
const INCLUDE_DEBUG_MESSAGE = 1;
|
||||||
const INCLUDE_TRACE = 2;
|
const INCLUDE_TRACE = 2;
|
||||||
|
const RETHROW_RESOLVER_EXCEPTIONS = 4;
|
||||||
|
|
||||||
private static $internalErrorMessage = 'Internal server error';
|
private static $internalErrorMessage = 'Internal server error';
|
||||||
|
|
||||||
@ -30,8 +31,10 @@ class FormattedError
|
|||||||
* @param \Throwable $e
|
* @param \Throwable $e
|
||||||
* @param bool|int $debug
|
* @param bool|int $debug
|
||||||
* @param string $internalErrorMessage
|
* @param string $internalErrorMessage
|
||||||
*
|
|
||||||
* @return array
|
* @return array
|
||||||
|
* @throws Error
|
||||||
|
*
|
||||||
|
* @throws \Throwable
|
||||||
*/
|
*/
|
||||||
public static function createFromException($e, $debug = false, $internalErrorMessage = null)
|
public static function createFromException($e, $debug = false, $internalErrorMessage = null)
|
||||||
{
|
{
|
||||||
@ -41,6 +44,12 @@ class FormattedError
|
|||||||
Utils::getVariableType($e)
|
Utils::getVariableType($e)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($debug & self::RETHROW_RESOLVER_EXCEPTIONS > 0) {
|
||||||
|
if (!$e instanceof Error || $e->getPrevious()) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$debug = (int) $debug;
|
$debug = (int) $debug;
|
||||||
$internalErrorMessage = $internalErrorMessage ?: self::$internalErrorMessage;
|
$internalErrorMessage = $internalErrorMessage ?: self::$internalErrorMessage;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user