Automattic\WooCommerce\Vendor\GraphQL\Error
FormattedError::createFromException
Convert any exception to a Automattic\WooCommerce\Vendor\GraphQL spec compliant array.
This method only exposes the exception message when the given exception implements the ClientAware interface, or when debug flags are passed.
For a list of available debug flags @see \Automattic\WooCommerce\Vendor\GraphQL\Error\DebugFlag constants.
Method of the class: FormattedError{}
No Hooks.
Returns
SerializableError.
Usage
$result = FormattedError::createFromException( $exception, $debugFlag, ?string $internalErrorMessage ): array;
- $exception(Throwable) (required)
- .
- $debugFlag(int)
- .
Default:DebugFlag::NONE - ?string $internalErrorMessage
- .
Default:null
FormattedError::createFromException() FormattedError::createFromException code WC 10.9.1
public static function createFromException(\Throwable $exception, int $debugFlag = DebugFlag::NONE, ?string $internalErrorMessage = null): array
{
$internalErrorMessage ??= self::$internalErrorMessage;
$message = $exception instanceof ClientAware && $exception->isClientSafe()
? $exception->getMessage()
: $internalErrorMessage;
$formattedError = ['message' => $message];
if ($exception instanceof Error) {
$locations = array_map(
static fn (SourceLocation $loc): array => $loc->toSerializableArray(),
$exception->getLocations()
);
if ($locations !== []) {
$formattedError['locations'] = $locations;
}
if ($exception->path !== null && $exception->path !== []) {
$formattedError['path'] = $exception->path;
}
}
if ($exception instanceof ProvidesExtensions) {
$extensions = $exception->getExtensions();
if (is_array($extensions) && $extensions !== []) {
$formattedError['extensions'] = $extensions;
}
}
if ($debugFlag !== DebugFlag::NONE) {
$formattedError = self::addDebugEntries($formattedError, $exception, $debugFlag);
}
return $formattedError;
}