Automattic\WooCommerce\Vendor\GraphQL\Error
Error::createLocatedError
Given an arbitrary Error, presumably thrown while attempting to execute a Automattic\WooCommerce\Vendor\GraphQL operation, produce a new GraphQLError aware of the location in the document responsible for the original Error.
Method of the class: Error{}
No Hooks.
Returns
null. Nothing (null).
Usage
$result = Error::createLocatedError( $error, $nodes, ?array $path, ?array $unaliasedPath ): Error;
- $error(mixed) (required)
- .
- $nodes(iterable
|Node|null) - .
Default:null - ?array $path
- .
Default:null - ?array $unaliasedPath
- .
Default:null
Error::createLocatedError() Error::createLocatedError code WC 11.1.2
public static function createLocatedError($error, $nodes = null, ?array $path = null, ?array $unaliasedPath = null): Error
{
if ($error instanceof self) {
if ($error->isLocated()) {
return $error;
}
$nodes ??= $error->getNodes();
$path ??= $error->getPath();
$unaliasedPath ??= $error->getUnaliasedPath();
}
$source = null;
$originalError = null;
$positions = [];
$extensions = [];
if ($error instanceof self) {
$message = $error->getMessage();
$originalError = $error;
$source = $error->getSource();
$positions = $error->getPositions();
$extensions = $error->getExtensions();
} elseif ($error instanceof InvariantViolation) {
$message = $error->getMessage();
$originalError = $error->getPrevious() ?? $error;
} elseif ($error instanceof \Throwable) {
$message = $error->getMessage();
$originalError = $error;
} else {
$message = (string) $error;
}
$nonEmptyMessage = $message === ''
? 'An unknown error occurred.'
: $message;
return new static(
$nonEmptyMessage,
$nodes,
$source,
$positions,
$path,
$originalError,
$extensions,
$unaliasedPath
);
}