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
|
||||
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_TRACE = 2;
|
||||
const RETHROW_RESOLVER_EXCEPTIONS = 4;
|
||||
|
||||
public static function setInternalErrorMessage($msg);
|
||||
|
||||
|
@ -15,6 +15,7 @@ class FormattedError
|
||||
{
|
||||
const INCLUDE_DEBUG_MESSAGE = 1;
|
||||
const INCLUDE_TRACE = 2;
|
||||
const RETHROW_RESOLVER_EXCEPTIONS = 4;
|
||||
|
||||
private static $internalErrorMessage = 'Internal server error';
|
||||
|
||||
@ -30,8 +31,10 @@ class FormattedError
|
||||
* @param \Throwable $e
|
||||
* @param bool|int $debug
|
||||
* @param string $internalErrorMessage
|
||||
*
|
||||
* @return array
|
||||
* @throws Error
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public static function createFromException($e, $debug = false, $internalErrorMessage = null)
|
||||
{
|
||||
@ -41,6 +44,12 @@ class FormattedError
|
||||
Utils::getVariableType($e)
|
||||
);
|
||||
|
||||
if ($debug & self::RETHROW_RESOLVER_EXCEPTIONS > 0) {
|
||||
if (!$e instanceof Error || $e->getPrevious()) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
$debug = (int) $debug;
|
||||
$internalErrorMessage = $internalErrorMessage ?: self::$internalErrorMessage;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user