public static function createFromException($e, $debug = false, $internalErrorMessage = null)
    {
        Utils::invariant(
            $e instanceof Exception || $e instanceof Throwable,
            'Expected exception, got %s',
            Utils::getVariableType($e)
        );

        $internalErrorMessage = $internalErrorMessage ?: self::$internalErrorMessage;

        if ($e instanceof ClientAware) {
            $formattedError = [
                'message'  => $e->isClientSafe() ? $e->getMessage() : $internalErrorMessage,
                'extensions' => [
                    'category' => $e->getCategory(),
                ],
            ];
        } else {
            $formattedError = [
                'message'  => $internalErrorMessage,
                'extensions' => [
                    'category' => Error::CATEGORY_INTERNAL,
                ],
            ];
        }

        if ($e instanceof Error) {
            $locations = Utils::map(
                $e->getLocations(),
                static function (SourceLocation $loc) {
                    return $loc->toSerializableArray();
                }
            );
            if (! empty($locations)) {
                $formattedError['locations'] = $locations;
            }
            if (! empty($e->path)) {
                $formattedError['path'] = $e->path;
            }
            if (! empty($e->getExtensions())) {
                $formattedError['extensions'] = $e->getExtensions() + $formattedError['extensions'];
            }
        }

        if ($debug) {
            $formattedError = self::addDebugEntries($formattedError, $e, $debug);
        }

        return $formattedError;
    }
public static function createFromException($e, $debug = false, $internalErrorMessage = null)
    {
        Utils::invariant(
            $e instanceof Exception || $e instanceof Throwable,
            'Expected exception, got %s',
            Utils::getVariableType($e)
        );

        $internalErrorMessage = $internalErrorMessage ?: self::$internalErrorMessage;

        if ($e instanceof ClientAware) {
            $formattedError = [
                'message'  => $e->isClientSafe() ? $e->getMessage() : $internalErrorMessage,
                'extensions' => [
                    'category' => $e->getCategory(),
                ],
            ];
        } else {
            $formattedError = [
                'message'  => $internalErrorMessage,
                'extensions' => [
                    'category' => Error::CATEGORY_INTERNAL,
                ],
            ];
        }

        if ($e instanceof Error) {
            $locations = Utils::map(
                $e->getLocations(),
                static function (SourceLocation $loc) {
                    return $loc->toSerializableArray();
                }
            );
            if (! empty($locations)) {
                $formattedError['locations'] = $locations;
            }
            if (! empty($e->path)) {
                $formattedError['path'] = $e->path;
            }
            if (! empty($e->getExtensions())) {
                $formattedError['extensions'] = $e->getExtensions() + $formattedError['extensions'];
            }
        }

        if ($debug) {
            $formattedError = self::addDebugEntries($formattedError, $e, $debug);
        }

        return $formattedError;
    }
public static function createFromException ( $ e , $ debug = false , $ internalErrorMessage = null ) { Utils :: invariant ( $ e instanceof Exception || $ e instanceof Throwable , 'Expected exception, got %s' , Utils :: getVariableType ( $ e ) ) ; $ internalErrorMessage = $ internalErrorMessage ? : self :: $ internalErrorMessage ; if ( $ e instanceof ClientAware ) { $ formattedError = [ 'message' => $ e -> isClientSafe ( ) ? $ e -> getMessage ( ) : $ internalErrorMessage , 'extensions' => [ 'category' => $ e -> getCategory ( ) , ] , ] ; } else { $ formattedError = [ 'message' => $ internalErrorMessage , 'extensions' => [ 'category' => Error :: CATEGORY_INTERNAL , ] , ] ; } if ( $ e instanceof Error ) { $ locations = Utils :: map ( $ e -> getLocations ( ) , static function ( SourceLocation $ loc ) { return $ loc -> toSerializableArray ( ) ; } ) ; if ( ! empty ( $ locations ) ) { $ formattedError [ 'locations' ] = $ locations ; } if ( ! empty ( $ e -> path ) ) { $ formattedError [ 'path' ] = $ e -> path ; } if ( ! empty ( $ e -> getExtensions ( ) ) ) { $ formattedError [ 'extensions' ] = $ e -> getExtensions ( ) + $ formattedError [ 'extensions' ] ; } } if ( $ debug ) { $ formattedError = self :: addDebugEntries ( $ formattedError , $ e , $ debug ) ; } return $ formattedError ; }
Standard GraphQL error formatter. Converts any exception to array
conforming to GraphQL spec.

This method only exposes exception message when exception implements ClientAware interface
(or when debug flags are passed).

For a list of available debug flags see GraphQL\Error\Debug constants.

@param Throwable $e
@param bool|int  $debug
@param string    $internalErrorMessage

@return mixed[]

@throws Throwable

@api
Standard GraphQL error formatter . Converts any exception to array conforming to GraphQL spec .