FormattedError
in package
This class is used for [default error formatting](error-handling.md).
It converts PHP exceptions to spec-compliant errors and provides tools for error debugging.
Table of Contents
- $internalErrorMessage : string
- addDebugEntries() : array<string|int, mixed>
- Decorates spec-compliant $formattedError with debug entries according to $debug flags (@see \GraphQL\Error\DebugFlag for available flags)
- create() : array<string|int, mixed>
- createFromException() : array<string|int, mixed>
- Standard GraphQL error formatter. Converts any exception to array conforming to GraphQL spec.
- createFromPHPError() : array<string|int, mixed>
- prepareFormatter() : callable
- Prepares final error formatter taking in account $debug flags.
- printError() : string
- Prints a GraphQLError to a string, representing useful location information about the error's position in the source.
- printVar() : string
- setInternalErrorMessage() : mixed
- Set default error message for internal errors formatted using createFormattedError().
- toSafeTrace() : array<string|int, mixed>
- Returns error trace as serializable array
- getColumnOffset() : int
- highlightSourceAtLocation() : string
- Render a helpful description of the location of the error in the GraphQL Source document.
- lpad() : string
- whitespace() : string
Properties
$internalErrorMessage
private
static string
$internalErrorMessage
= 'Internal server error'
Methods
addDebugEntries()
Decorates spec-compliant $formattedError with debug entries according to $debug flags (@see \GraphQL\Error\DebugFlag for available flags)
public
static addDebugEntries(array<string|int, mixed> $formattedError, Throwable $e, int $debugFlag) : array<string|int, mixed>
Parameters
- $formattedError : array<string|int, mixed>
- $e : Throwable
- $debugFlag : int
Tags
Return values
array<string|int, mixed> —create()
public
static create(string $error[, array<string|int, SourceLocation> $locations = [] ]) : array<string|int, mixed>
Parameters
- $error : string
- $locations : array<string|int, SourceLocation> = []
Tags
Return values
array<string|int, mixed> —createFromException()
Standard GraphQL error formatter. Converts any exception to array conforming to GraphQL spec.
public
static createFromException(Throwable $exception[, int $debug = DebugFlag::NONE ][, string $internalErrorMessage = null ]) : array<string|int, mixed>
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\DebugFlag constants.
Parameters
- $exception : Throwable
- $debug : int = DebugFlag::NONE
- $internalErrorMessage : string = null
Tags
Return values
array<string|int, mixed> —createFromPHPError()
public
static createFromPHPError(ErrorException $e) : array<string|int, mixed>
Parameters
- $e : ErrorException
Tags
Return values
array<string|int, mixed> —prepareFormatter()
Prepares final error formatter taking in account $debug flags.
public
static prepareFormatter(callable|null $formatter, int $debug) : callable
If initial formatter is not set, FormattedError::createFromException is used
Parameters
- $formatter : callable|null
- $debug : int
Return values
callable —printError()
Prints a GraphQLError to a string, representing useful location information about the error's position in the source.
public
static printError(Error $error) : string
Parameters
- $error : Error
Return values
string —printVar()
public
static printVar(mixed $var) : string
Parameters
- $var : mixed
Return values
string —setInternalErrorMessage()
Set default error message for internal errors formatted using createFormattedError().
public
static setInternalErrorMessage(string $msg) : mixed
This value can be overridden by passing 3rd argument to createFormattedError()
.
Parameters
- $msg : string
Return values
mixed —toSafeTrace()
Returns error trace as serializable array
public
static toSafeTrace(Throwable $error) : array<string|int, mixed>
Parameters
- $error : Throwable
Return values
array<string|int, mixed> —getColumnOffset()
private
static getColumnOffset(Source $source, SourceLocation $location) : int
Parameters
- $source : Source
- $location : SourceLocation
Return values
int —highlightSourceAtLocation()
Render a helpful description of the location of the error in the GraphQL Source document.
private
static highlightSourceAtLocation(Source $source, SourceLocation $location) : string
Parameters
- $source : Source
- $location : SourceLocation
Return values
string —lpad()
private
static lpad(int $len, mixed $str) : string
Parameters
- $len : int
- $str : mixed
Return values
string —whitespace()
private
static whitespace(int $len) : string
Parameters
- $len : int