Automattic\WooCommerce\Vendor\GraphQL\Error
FormattedError::printError
Prints a GraphQLError to a string, representing useful location information about the error's position in the source.
Method of the class: FormattedError{}
No Hooks.
Returns
null. Nothing (null).
Usage
$result = FormattedError::printError( $error ): string;
- $error(Error) (required)
- .
FormattedError::printError() FormattedError::printError code WC 10.9.1
public static function printError(Error $error): string
{
$printedLocations = [];
$nodes = $error->nodes;
if (isset($nodes) && $nodes !== []) {
foreach ($nodes as $node) {
$location = $node->loc;
if (isset($location)) {
$source = $location->source;
if (isset($source)) {
$printedLocations[] = self::highlightSourceAtLocation(
$source,
$source->getLocation($location->start)
);
}
}
}
} elseif ($error->getSource() !== null && $error->getLocations() !== []) {
$source = $error->getSource();
foreach ($error->getLocations() as $location) {
$printedLocations[] = self::highlightSourceAtLocation($source, $location);
}
}
return $printedLocations === []
? $error->getMessage()
: implode("\n\n", array_merge([$error->getMessage()], $printedLocations)) . "\n";
}